Importing Outlook contacts into an Access database.
Posted on 2004-10-15
Would like to create an Access database that automatically imports Outlook contact information from other user's email accounts.
An expert-exchanger was kind enough to provide me with the following code (which works perfectly), however, I am wondering if it can be modified to go the extra step of pulling not only my contacts but contact's from other email accounts to which I have rights.
I can accomplish this manually by simply going, 'File', 'Get External Data', 'Import' and then selecting 'Outlook' as a File Type but I sure would like to automate this.
Private Sub cmdGetContacts_Click()
Dim myRecipient As ContactItem
Set myOlApp = CreateObject("Outlook.Application")
Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myFolder = myNamespace.GetDefaultFolder(olFolderContacts)
For iLoop = 1 To myFolder.Items.Count
If TypeName(myFolder.Items(iLoop)) = "ContactItem" Then
Set myRecipient = myFolder.Items(iLoop)
sSQL = "INSERT INTO MasterContactList2 VALUES ('" & myRecipient.LastName & "','" & myRecipient.FirstName & "')"
Set myOlApp = Nothing
MsgBox "Completed Successfully", vbInformation, "Ok"