Solved

Importing Outlook contacts into an Access database.

Posted on 2004-10-15
7
246 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

914 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now