Here's a simple example that should give you the basics you're looking for.
Private olApp As Outlook.Application Private db As DAO.Database
Public Sub DoMyRoutine() Dim olMailItem As Outlook.MailItem, rs As DAO.Recordset, CopyFields As Collection Dim tstr As Variant
Set olApp = Outlook.Application Set db = OpenDatabase("C:\TEMP\temp.mdb") Set rs = db.OpenRecordset("data")
Set CopyFields = GetFieldCopyInfo() If CopyFields.Count = 0 Then MsgBox "User cancelled operation or no fields selected." Exit Sub End If
With rs For Each olMailItem In olApp.ActiveExplorer.Selection .AddNew For Each tstr In CopyFields If tstr = "DateSent" Then !DateSent = olMailItem.SentOn If tstr = "SenderName" Then !SenderName = olMailItem.SenderName If tstr = "SenderEmail" Then !SenderEmail = olMailItem.SenderEmailAddress Next tstr .Update Next olMailItem End With End Sub
Private Function GetFieldCopyInfo() As Collection Dim tcoll As New Collection
Load UserForm1 With UserForm1 .Show vbModal If .cbDateSent Then tcoll.Add "DateSent" If .cbSenderName Then tcoll.Add "SenderName" If .cbSenderEmail Then tcoll.Add "SenderEmail" End With Unload UserForm1
Set GetFieldCopyInfo = tcoll End Function
You'll need to create a form with the appropriate checkboxes and an "OK" button. I've also assumed you're using DAO to interface with a Jet DB. Hope this helps.
|