Access.2007.VBA.Bibl..

(John Hannent) #1
If you always synchronize your Access contacts to the same Outlook folder, you can
comment out the SelectContactFoldercode segment and insert a hard-coded
folder path instead; if you want to use the default local Contacts folder, just remove the apostrophe
on the line ‘Set fldContacts = nms.GetDefaultFolder(olFolderContacts), and either
comment out or delete the SelectContactFoldercode segment.

The other procedure, CreateDenormalizedContactsTable, is considerably more complex,
because it has to take data from five linked tables, creating one record per contact and updating its
fields from different tables:

Public Function CreateDenormalizedContactsTable()
‘Called from cmdForms_Click on fmnuMain

On Error GoTo ErrorHandler

Dim lngTargetID As Long
Dim strQueryContacts As String
Dim strQueryContactIDs As String
Dim strQueryCompanyIDs As String
Dim strQueryContactAddresses As String
Dim strTargetCustomerID As String

Set dbs = CurrentDb
strQueryContacts = “qryAccessContacts”
strQueryContactIDs = “qryContactIDsPhones”
strQueryCompanyIDs = “qryCompanyIDsPhones”
strQueryContactAddresses = “qryContactAddresses”

Clear tables of old data.

DoCmd.SetWarnings False
strTable = “tblAccessContacts”
strSQL = “DELETE * FROM “ & strTable
DoCmd.RunSQL strSQL

The rstTarget recordset is based on tblAccessContacts; this is the table to be filled with denormal-
ized data. rstSource represents the first table of linked Access data, tblContactInfo. Information
from this table is written to matching fields in the target table, with special handling for attach-
ments (see the section on attachments for more information on this topic):

Set rstSource = dbs.OpenRecordset(strQueryContacts, _
dbOpenDynaset)
Set rstTarget = dbs.OpenRecordset(strTable, _
dbOpenDynaset)

Do While Not rstSource.EOF

Create one record in the target table per contact, and write company and contact data to it; also
create one record in the match table per contact, for use in comparing contacts:

TIPTIP


Part II Writing VBA Code to Exchange Data between Office Components

Free download pdf