Link to home
Start Free TrialLog in
Avatar of WNottsC
WNottsCFlag for Afghanistan

asked on

How do I use Office 2007 embeded macro's in office 2003?

I have looked at the builtin templates in MSAccess 2007 (in particular contacts).  They have some very nice functions such as add from outlook,  show/hide fields all of which are done from embedded macros.  How can I find out what the code behind these are so that I can use the code in a clients MSAccess 2003 database
ASKER CERTIFIED SOLUTION
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of WNottsC

ASKER

is there any way in MSAccess 2003 to do this?
Avatar of WNottsC

ASKER

this is fine for connecting directly to the contacts table

but how do I maintain a table in MSaccess and then on the attached form I can have buttons to either add a contact from outlook or I can add a manual record from the form.  It would also be useful to be able to have a button to sync the two at times as well?
Avatar of WNottsC

ASKER

Thanks for your help I have found the code to import contacts from outlook to MSAccess:-

Sub ImportContactsFromOutlook()

   ' This code is based in Microsoft Access.

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


   ' 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.AddNew
            rst!FirstName = c.FirstName
            rst!LastName = c.LastName
            rst!Address = c.BusinessAddressStreet
            rst!City = c.BusinessAddressCity
            rst!State = c.BusinessAddressState
            rst!Zip_Code = c.BusinessAddressPostalCode
            ' Custom Outlook properties would look like this:
            ' rst!AccessFieldName = c.UserProperties("OutlookPropertyName")
            rst.Update
         End If
      Next i
      rst.Close
      MsgBox "Finished."
   Else
      MsgBox "No contacts to export."
   End If

End Sub


This seems to import all,  how do I change this to open up the outlook global address list selector and use the contact I select?