Sub ScanJournals()
'Set up Outlook objects.
Dim ol As New Outlook.Application
Dim olns As Outlook.Namespace
Dim cf As Outlook.MAPIFolder
Dim c As Outlook.JournalItem
Dim objItems As Outlook.Items
Dim Prop As Outlook.UserProperty
Dim mvAtt As Outlook.Attachment
Dim mvX As Long
Dim mvXatt As Long
Dim DB As DAO.Database
Dim rstJournal As DAO.Recordset
Dim rstAttachments As DAO.Recordset
Set olns = ol.GetNamespace("MAPI")
Set cf = olns.GetDefaultFolder(olFolderJournal)
Set objItems = cf.Items
iNumContacts = objItems.Count
Set DB = CurrentDb
Set rstJournal = DB.OpenRecordset("Select * from Journal", dbOpenDynaset, dbSeeChanges)
Set rstAttachments = DB.OpenRecordset("Select * from Attachments", dbOpenDynaset, dbSeeChanges)
If iNumContacts <> 0 Then
For i = 1 To iNumContacts
Set c = objItems(i)
'Save the Journal Entry
rstJournal.AddNew
rstJournal![journal type] = c.Type
rstJournal!Subject = c.Subject
rstJournal![start date] = c.Start
rstJournal!Categories = c.Categories
rstJournal!Companies = c.Companies
rstJournal![Contact (Name)] = c.ContactNames
rstJournal!Duration = c.Duration
rstJournal![billing information] = c.BillingInformation
rstJournal!Mileage = c.Mileage
rstJournal!Body = c.Body
rstJournal.Update
rstJournal.Bookmark = rstJournal.LastModified
mvXatt = 1
For Each Att In c.Attachments
Set mvAtt = c.Attachments(mvXatt)
rstAttachments.AddNew
rstAttachments!journalid = rstJournal!journalid
rstAttachments!Description = mvAtt.FileName
rstAttachments!FileName = "c:\temp\alchemy\" & rstJournal!journalid & mvXatt & Mid(mvAtt.FileName, InStr(mvAtt.FileName, "."), 10)
mvAtt.SaveAsFile rstAttachments!FileName
rstAttachments.Update
mvXatt = mvXatt + 1
Next Att
Next i
Else
MsgBox "No contacts to export."
End If
rstAttachments.Close
rstJournal.Close
Set DB = Nothing
End Sub
|