To update data in tblContactAddresses, if there is data in any of the Business address fields, the
strAddressType variable is set to Business, and the code searches for matching records in
tblContactAddresses. If none are found, a new address record is created; if a record is found, its
fields are updated from the appropriate fields in tblAccessContacts. The Home and Other address
fields are handled similarly:
strTarget = “tblContactAddresses”
Set rstTarget = dbs.OpenRecordset(strTarget, _
dbOpenDynaset)
Update Business address info.
If Nz(rstSource!BusinessAddressStreet) <> “” Or _
Nz(rstSource!BusinessAddressPostOfficeBox) <> “” _
Or Nz(rstSource!BusinessAddressCity) <> “” _
Or Nz(rstSource!BusinessAddressState) <> “” _
Or Nz(rstSource!BusinessAddressPostalCode) <> “” _
Or Nz(rstSource!BusinessAddressCountry) <> “” Then
strAddressType = “Business”
strSearch = “[ContactID] = “ & lngContactID _
& “ And [AddressType] = “ & Chr$(39) _
& strAddressType & Chr$(39)
Debug.Print “Search string: “ & strSearch
rstTarget.FindFirst strSearch
If rstTarget.NoMatch = True Then
Create a new contact address record in the target table.
rstTarget.AddNew
rstTarget![ContactID] = lngContactID
rstTarget![AddressType] = strAddressType
Else
rstTarget.Edit
End If
rstTarget![StreetAddress] = _
Nz(rstSource!BusinessAddressStreet)
rstTarget![POBox] = _
Nz(rstSource!BusinessAddressPostOfficeBox)
rstTarget![City] = _
Nz(rstSource!BusinessAddressCity)
rstTarget![StateOrProvince] = _
Nz(rstSource!BusinessAddressState)
rstTarget![PostalCode] = _
Nz(rstSource!BusinessAddressPostalCode)
rstTarget![Country] = _
Nz(rstSource!BusinessAddressCountry)
rstTarget.Update
End If
Synchronizing Access and Outlook Contacts 11