Solved

Importing Outlook contacts into an Access database.

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

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…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

747 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

13 Experts available now in Live!

Get 1:1 Help Now