Please help me alter this code (import from Outlook)

A

Anders Berlin

I have downloaded the following code from
http://support.microsoft.com/?id=290792, which works fine to import CONTACTS
from Outlook into a table in Access. How do I change this code so it imports
the actual EMAILS in my inbox into a table in Access? I know it is possible
but I just don't know how to alter the code correctly. Here is the code:


Sub ImportContactsFromOutlook()

' This code is based in Microsoft Access.

' Set up DAO objects (uses existing "tblContacts" table)
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("tblContacts")


' Set up Outlook objects.
Dim ol As New Outlook.Application
Dim olns As Outlook.Namespace
Dim cf As Outlook.MAPIFolder
Dim c As Outlook.ContactItem
Dim objItems As Outlook.Items
Dim Prop As Outlook.UserProperty

Set olns = ol.GetNamespace("MAPI")
Set cf = olns.GetDefaultFolder(olFolderContacts)
Set objItems = cf.Items
iNumContacts = objItems.Count
If iNumContacts <> 0 Then
For i = 1 To iNumContacts
If TypeName(objItems(i)) = "ContactItem" Then
Set c = objItems(i)
rst.AddNew
rst!FirstName = c.FirstName
rst!LastName = c.LastName
rst!Address = c.BusinessAddressStreet
rst!City = c.BusinessAddressCity
rst!State = c.BusinessAddressState
rst!Zip_Code = c.BusinessAddressPostalCode
' Custom Outlook properties would look like this:
' rst!AccessFieldName = c.UserProperties("OutlookPropertyName")
rst.Update
End If
Next i
rst.Close
MsgBox "Finished."
Else
MsgBox "No contacts to export."
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top