Re: importing from Outlook to Access or vice versa

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Cheryl Fischer (cherylfischer_at_NOSPAMmsn.com)
Date: 02/18/04


Date: Wed, 18 Feb 2004 17:19:44 -0600

You can use Automation to export contact data from Access to Outlook. To
use the code below, you will need to add a reference to the Microsoft
Outlook xx.x Object Library (where xx.x is the version you are using) and
the Microsoft DAO x.xx Object Library (where x.xx is the version appropriate
to your version of Access).

You will need, of course, to change the table and field names found here to
match the ones you are using.

    Dim oOutlook As New Outlook.Application
    Dim colItems As Items
    Dim rsCont As DAO.Recordset
    Dim db as DAO.Database
    Dim strSQL As String
    Dim strMsg As String

    strSQL = "Select * from tblContacts;"

    Set db = CurrentDB
    Set rsCont = db.OpenRecordset(strSQL, dbOpenDynaset)

    'Get a reference to the Items collection of the contacts folder.
    Set colItems = oOutlook.GetNamespace("MAPI"). _
                        GetDefaultFolder(olFolderContacts).Items
    rsCont.MoveFirst
    Do Until rsCont.EOF
            With colItems.Add
                .Email1Address = Nz(rsCont!emailaddr)
                .FirstName = Nz(rsCont!ContactFirstName)
                .LastName = Nz(rsCont!ContactLastName)
                .BusinessAddressStreet = Nz(rsCont!BusinessAddress, "")
                .FullName = Nz(rsCont!ContactName)
                .BusinessAddressCity = Nz(tblContacts!City)
                .BusinessAddressState = Nz(tblContacts!Region)
                .BusinessAddressPostalCode = Nz(tblContacts!PostalCode)
                .BusinessAddressCountry = Nz(tblContacts!Country)
                .BusinessTelephonePhone = Nz(tblContacts!Phone)
                .BusinessFaxNumber = Nz(tblContacts!Fax)
                .CompanyName = Nz(tblContacts!CompanyName)
                .JobTitle = Nz(tblContacts!ContactTitle)

                .Save
            End With
        rsCont.MoveNext
    Loop
    rsCont.Close
    Set rsCont=Nothing
MsgBox "Done!"

hth,

--
Cheryl Fischer, MVP Microsoft Access
Law/Sys Associates, Houston, TX
"Michelle" <madhouse65@elvis.com> wrote in message
news:1278901c3f668$909b89d0$a001280a@phx.gbl...
> My question is this:
>
> I am working for someone and they want names and
> addresses in an Access database. Great. Done that. Real
> new to Access, but did it. Then I have to put the same
> info in her Outlook Contacts list. Is there anyway to
> pull the information from one to the other without having
> to type it twice? I asked a teacher of Access and she did
> not know. But it is very time consuming to type all that
> twice. Please help!!!
>
>
> Michelle


Relevant Pages

  • Re: Mail Merge to email with attachments
    ... Dim Source As Document, Maillist As Document, TempDoc As Document ... ' Check if Outlook is running. ... Set oOutlookApp = CreateObject ... Microsoft Outlook library and select it. ...
    (microsoft.public.outlook.program_vba)
  • Re: Isolating embedded pictures in emails
    ... Microsoft Office and Microsoft Outlook Object Library selected ... > Dim colAttachments As Outlook.Attachments ... > Set colAttachments = Nothing ...
    (microsoft.public.outlook.general)
  • Re: Extra Excel Instance
    ... Next I commented out all the code that formatted the excel worksheet. ... I had to add an extra declaration for stnm -- Dim stnm As String ... Next I added the code for outlook back in by uncommenting it. ... Microsoft Access 9.0 Object Library ...
    (microsoft.public.access.modulesdaovba)
  • Add contact to outlook 2003 code / strange error message
    ... I now have code working that will add a contact to outlook 2003, however, Microsoft Outlook is giving the following warning message: ... ' This code is based in Microsoft Access. ... Dim ol As Object 'New Outlook.Application ... MsgBox "Exported current contact to MS Outlook.", vbInformation, "Export ...
    (comp.databases.ms-access)
  • Re: e_mails
    ... e-mails up on outlook express or microsoft, really dont understand all of ... I've sent it to your email address twice now - didn't you get it? ...
    (microsoft.public.windowsmedia)