Solved

Importing Outlook contacts into an Access database.

Posted on 2004-10-15
7
257 Views
Last Modified: 2008-03-06
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.

Possible?????


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 & "')"
      CurrentDb.Execute (sSQL)
    End If
  Next iLoop
  Set myOlApp = Nothing
  MsgBox "Completed Successfully", vbInformation, "Ok"
End Sub
0
Comment
Question by:mbath20110
  • 2
  • 2
7 Comments
 
LVL 15

Accepted Solution

by:
will_scarlet7 earned 250 total points
ID: 12320013
Changing the myFolder as below will allow you to pick the folder that you want to import from:

Private Sub cmdGetContacts_Click()
  Dim myRecipient  As ContactItem
  Set myOlApp = CreateObject("Outlook.Application")
  Set myNamespace = myOlApp.GetNamespace("MAPI")
  Set myFolder = myNamespace.PickFolder

  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 & "')"
      CurrentDb.Execute (sSQL)
    End If
  Next iLoop
  Set myOlApp = Nothing
  MsgBox "Completed Successfully", vbInformation, "Ok"
End Sub
0
 

Author Comment

by:mbath20110
ID: 12320517
Great!!

Figured it was something like that.  However, I'm struggling a bit with the syntax.

If I go the manual route, when I come to the dialog box that asks me to specify the particular user account, the user I want is listed as: 'Flores, Edmee'.

Soooo, how would that look?  

Set myFolder = myNamespace.Flores, Edmee?
Set myFolder = myNamespace.FloresEdmee?
Set myFolder = myNamespace.EdmeeFlores?

so far I'm getting a runtime:

Object doesn't support this method or property.
0
 
LVL 15

Expert Comment

by:will_scarlet7
ID: 12320804
Sorry I'm not real versed in Exchange environments... (I've never worked with it)
0
 
LVL 49

Assisted Solution

by:Gustav Brock
Gustav Brock earned 250 total points
ID: 12506848
How about:

  Set myFolder = myNamespace.Items("Flores, Edmee")

or just:

  Set myFolder = myNamespace("Flores, Edmee")

/gustav
0
 

Author Comment

by:mbath20110
ID: 12507723
I'll give it a try ...   thanks!!!
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

806 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question