WNottsC
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
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?
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("t blContacts ")
' 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(olFo lderContac ts)
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.BusinessAddressPostalCod e
' Custom Outlook properties would look like this:
' rst!AccessFieldName = c.UserProperties("OutlookP ropertyNam e")
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?
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("t
' 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(olFo
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.BusinessAddressPostalCod
' Custom Outlook properties would look like this:
' rst!AccessFieldName = c.UserProperties("OutlookP
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?
ASKER