Const olPublicFoldersAllPublicFolders = 18
Dim olkApp, olkSes, olkFld, olkItm, adoCon
Dim a, b, c, d
Set adoCon = CreateObject("ADODB.Connection")
'Change the database file name and path on the next line'
adoCon.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccess2007file.accdb;Persist Security Info=False;"
Set olkApp = CreateObject("Outlook.Application")
Set olkSes = olkApp.GetNamespace("MAPI")
'Change the profile name on the next line as needed'
olkSes.Logon "Outlook"
'Change My Folder to the name of your folder on the next line'
Set olkFld = olkSes.GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders("My Folder")
For Each olkItm In olkFld.Items
With olkItm
'Change the fields on the next 4 lines. Add additional fields as needed.'
a = .Subject
b = .ReceivedTime
c = .SenderName
'Change the property name on the next line'
d = .UserProperties.Item("Your Prop Name").Value
End With
'Edit the SQL command as needed'
olkCon.Execute "INSERT INTO SomeTableName (FieldName1,FieldName2,FieldName3,FieldName4) VALUES('" & a & "','" & b & "','" & c & "','" & d & "')"
Next
adoCon.Close
Set adoCon = Nothing
Set olkFld = Nothing
olkSes.Logoff
Set olkSes = Nothing
Set olkApp = Nothing
msgbox "Finished!"
|