Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2004

    Unhappy Unanswered: Importing Data from Outlook into Access

    Hope someone out there can help me - this one has got me stuck!

    I am trying to build a module in access that will import a list of contacts from outlook into an access contacts table.

    The problem seems to be that two of the field names in access have a space in them and the code I have wont accept it. The two line of code that are a problem are:

    rst!FirstName = c.FirstName
    rst!LastName = c.LastName

    My access field names are "First Name" and "Last Name".

    I tried the following formats, none of which would work:

    rst![First Name] = c.FirstName
    rst!First_Name = c.FirstName
    rst![First_Name] = c.FirstName
    rst!First.Name = c.FirstName
    rst!("First Name") = c.FirstName

    etc, etc.

    Can anyone out there help me???? Please!!!

    The rest of the code is below:

    Sub ImportContactsFromOutlook()

    ' This code is based in Microsoft Access.

    ' Set up DAO objects (uses existing "Prospects" table)
    Dim rst As DAO.Recordset
    Set rst = CurrentDb.OpenRecordset("Prospects")

    ' Set up Outlook objects.
    Dim ol As New Outlook.Application
    Dim olns As Outlook.NameSpace
    Dim cf As Outlook.MAPIFolder
    Dim c As Outlook.ContactItem
    Dim objItems As Outlook.Items
    Dim Prop As Outlook.UserProperty

    Set olns = ol.GetNamespace("MAPI")
    Set cf = olns.GetDefaultFolder(olFolderContacts)
    Set objItems = cf.Items
    iNumContacts = objItems.Count
    If iNumContacts <> 0 Then
    For i = 1 To iNumContacts
    If TypeName(objItems(i)) = "ContactItem" Then
    Set c = objItems(i)
    rst!FirstName = c.FirstName
    rst!LastName = c.LastName

    rst!City = c.BusinessAddressCity
    rst!State = c.BusinessAddressState
    rst!ZIP = c.BusinessAddressPostalCode
    ' Custom Outlook properties would look like this:
    ' rst!AccessFieldName = c.UserProperties("OutlookPropertyName")
    End If
    Next i
    MsgBox "Finished."
    MsgBox "No contacts to export."
    End If

    End Sub

  2. #2
    Join Date
    Jan 2004
    Vancouver, WA
    Dump the bang. Try rst1.Fields("First Name").Value or rst1("First Name").Value.

  3. #3
    Join Date
    Jul 2004

    Talking Thanks!!!

    It worked! Thanks very very much!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts