Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2003

    Exclamation Unanswered: Import CustomerID from Outlook contacts


    I use the code bellow to import all contacts fields from Outlook to Access 2000. Every thing is find except for the field CustomerID.

    The value of CustomerID is null for all records in Access table after importation. Why?

    I'm looking the have a unique identification field after importation. And, over the time (and many importation), I'm looking to have the same ID for a specific contact (even if I remove or add contacts in Outlook).

    Thanks for your Help!


    Function ImportFromOutlook()

    Dim appOutlook As New Outlook.Application
    Dim nms As Outlook.NameSpace

    Dim fld As Outlook.MAPIFolder
    Dim itm As Object
    Dim con As Outlook.ContactItem
    Dim dbs As DAO.Database
    Dim rst As DAO.Recordset
    Dim strTable As String

    On Error Resume Next

    'Turn warning off.
    DoCmd.SetWarnings False

    'Delete old tables.
    DoCmd.DeleteObject objecttype:=acTable, objectname:="tblOutlookContacts"

    'Make a fresh copy of the Access table to be filled with contact data.

    strTable = "tblOutlookContacts"
    DoCmd.CopyObject , newname:=strTable, sourceobjecttype:=acTable, sourceobjectname:="zstblOutlookContacts"

    On Error GoTo ErrorHandler

    'Set reference to the default local Outlook Contacts folder.
    Set nms = appOutlook.GetNamespace("MAPI")
    Set fld = nms.GetDefaultFolder(olFolderContacts)
    For Each itm In fld.Items

    'Check whether the item is a contact item.
    If itm.Class = olContact Then
    Set dbs = CurrentDb
    Set rts = dbs.OpenRecordset(strTable, dbOpenTable)
    Debug.Print "Processing " & Nz(itm.FullName) & " item"
    With rts
    !CustomerID = Nz(itm.CustomerID)
    !FullName = Nz(itm.FullName)
    !Title = Nz(itm.Title)
    !FirstName = Nz(itm.FirstName)
    !MiddleName = Nz(itm.MiddleName)
    !CompanyName = Nz(itm.CompanyName)
    !BusinessAddressStreet = Nz(itm.BusinessAddressStreet)
    !BusinessAddressCity = Nz(itm.BusinessAddressCity)
    !BusinessAddressState = Nz(itm.BusinessAddressState)
    !BusinessAddressCountry = Nz(itm.BusinessAddressCountry)
    !Categories = Nz(itm.Categories)
    !Email1Address = Nz(itm.Email1Address)
    End With
    End If
    Next itm

    MsgBox "All contacts imported!"
    DoCmd.OpenTable strTable

    Exit Function

    MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
    Resume ErrorHandlerExit

    End Function


  2. #2
    Join Date
    Nov 2002
    San Francisco

    Re: Import CustomerID from Outlook contacts

    in order to keep your CustomerIDs in both and also UNIQUE in both, I'd recommend to have one table which will have just one AutoID field, when you create new record in MS Access or Outlook, you always create new record in this table, red it and then delete it. This will guarantee that you will have unique number accross both sources.... the best would be to have this table on SQL server and call it using SOAP :-)

    it's very easy to do it for MS Access table (your OrderID will be just LONG, no autonumber). When you create new Customer, look to this special ID table and create CustomerID ....

    I highly recommend to use existing field in Outlook and not your cusom field (you will prevent lot of problems not only during sync with PDA...). I used BILLING ID field in the past. Then you can have procedure under SAVE event in outlook form, which will automatically stick unique customerID to that record or if you use Exchange Server it would be the best to have server side function.....

    if you want to keep it simple, stick CustomerID from MS Access to Billing no in Outlook when you sync... then you know new records.....


  3. #3
    Join Date
    Jan 2003
    And do you know why the value of CustomerID is null in Access after importation from Outlook?

  4. #4
    Join Date
    Nov 2002
    San Francisco
    cuaze CustomerID is your custom field and you cannot call custom fields like this, it is part of different collection.

    istead of

    Last edited by playernovis; 01-24-03 at 20:33.

Posting Permissions

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