Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Importing Outlook contacts into an Access database.

Posted on 2004-10-15
7
Medium Priority
?
281 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
7 Comments
 
LVL 15

Accepted Solution

by:
will_scarlet7 earned 1000 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 51

Assisted Solution

by:Gustav Brock
Gustav Brock earned 1000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

721 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