strContactName = _
Nz(lst.Column(1, varItem))
strCompanyName = _
Nz(lst.Column(7, varItem))
strNameTitleCompany = _
Nz(lst.Column(2, varItem))
strWholeAddress = Nz(lst.Column(5, varItem))
strSalutation = Nz(lst.Column(10, varItem))
strJobTitle = Nz(lst.Column(8, varItem))
strZipCode = Nz(lst.Column(6, varItem))
Add records to the table from the selected items in the ListBox:
With rst
.AddNew
![NameTitleCompany] = strNameTitleCompany
![WholeAddress] = strWholeAddress
![Salutation] = strSalutation
![TodayDate] = strLongDate
![CompanyName] = strCompanyName
![JobTitle] = strJobTitle
![ZipCode] = strZipCode
![ContactName] = strContactName
.Update
End With
NextContact:
Next varItem
rst.Close
Export the merge table data to a text file, to be used as the mail merge document’s data source:
strTextFile = strTemplatePath & “Merge Data.txt”
Debug.Print “Text file for merge: “ & strTextFile
DoCmd.TransferText transfertype:=acExportDelim, _
TableName:=strTable, _
FileName:=strTextFile, _
HasFieldNames:=True
Open a new merge document based on the selected template:
Set appWord = GetObject(Class:=”Word.Application”)
appWord.Documents.Add strWordTemplate
appWord.Visible = True
strDocName = appWord.ActiveDocument.Name
Debug.Print “Initial doc name: “ & strDocName
Part II Writing VBA Code to Exchange Data between Office Components