Access.2007.VBA.Bibl..

(John Hannent) #1
Loop

rstTarget.Close

strTitle = “Access tables updated”
strPrompt = “Linked Access tables of contact data “ _
& “updated from form”
MsgBox strPrompt, vbInformation + vbOKOnly, strTitle

ErrorHandlerExit:
On Error Resume Next
rstSource.Close
rstTarget.Close
Exit Sub

ErrorHandler:
MsgBox “Error No: “ & Err.Number _
& “; Description: “ & Err.Description
Resume ErrorHandlerExit

End Sub

In case you want to copy all the Access contacts to Outlook, or vice versa, there are two selections
on the Select Action combo box’s list that will let you do this. The “Copy All Access Contacts to
Outlook” selection runs the CopyAccessContactsToOutlookprocedure, which first puts up a
confirmation message to ensure that the user wants to wipe out the existing Outlook contacts, and
replace them with contacts copied from Access. If the user clicks Yes, the procedure first calls the
CreateDenormalizedContactsTableprocedure to write data to tblAccessContacts, and
then runs code that is similar to the code in the UpdateAllOutlookContactsprocedure,
except that it skips the searching and just creates all new Outlook contact items.

Similarly, the “Copy All Outlook Contacts to Access” selection runs the CopyAllOutlook
ContactsToAccessprocedure, which asks for confirmation, then runs the ImportOutlook
Contactsprocedure to write data from Outlook contacts to tblOutlookContacts, then runs code
that is similar to the code in the UpdateAllAccessContactsprocedure, except that it doesn’t
search for matching records, just creates new Access records for all the Outlook contact records.

When copying all Outlook contacts to Access, you will end up with Access and Outlook
contacts whose CustomerID values don’t match. This is because the ContactID field in
tblContactInfo is an AutoNumber field, so it can’t be set to a specific value. There are two ways to
deal with this discrepancy: Use the Compare by Name form if you don’t care whether the Customer
ID is the same in Access and Outlook; or select the “Copy All Access Contacts to Outlook” selection
to save the Access ContactID AutoNumber value back to the matching Outlook records.

NOTENOTE


Part II Writing VBA Code to Exchange Data between Office Components

Free download pdf