Use the following lines to set a reference to a custom Contacts folder, creating it if necessary. If set-
ting a reference to the folder fails, the folder will be created.
Set fld = nms.Folders(“Personal Folders”)
Set fldContacts = fld.Folders(“Contacts to Export”)
If fldContacts Is Nothing Then
Set fldContacts = _
fld.Folders.Add(“Contacts to Export”, _
olFolderContacts)
End If
On Error GoTo ErrorHandler
Clear the table of old data.
strSQL = “DELETE * FROM tblImportedContacts”
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
lngContactCount = 0
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(“tblImportedContacts”)
Iterate through contacts in selected Contacts folder and import them to the Access table.
For Each itm In fldContacts.Items
If itm.Class = olContact Then
Set con = itm
With con
strFirstName = Nz(.FirstName)
strLastName = Nz(.LastName)
strJobTitle = Nz(.JobTitle)
strWorkAddress = Nz(.BusinessAddressStreet)
strWorkCity = Nz(.BusinessAddressCity)
strWorkStateProv = Nz(.BusinessAddressState)
strWorkPostalCode = _
Nz(.BusinessAddressPostalCode)
strWorkCountry = Nz(.BusinessAddressCountry)
strHomeAddress = Nz(.HomeAddress)
strHomeCity = Nz(.HomeAddressCity)
strHomeStateProv = Nz(.HomeAddressState)
strHomePostalCode = Nz(.HomeAddressPostalCode)
strHomeCountry = Nz(.HomeAddressCountry)
strCompanyName = Nz(.CompanyName)
strEMail = Nz(.Email1Address)
strBusinessPhone = _
Nz(.BusinessTelephoneNumber)
strFaxNumber = Nz(.BusinessFaxNumber)
strMobilePhone = Nz(.MobileTelephoneNumber)
strSalutation = Nz(.NickName)
Part II Writing VBA Code to Exchange Data between Office Components