Microsoft Office Tutorials and References
In Depth Information
Merging Data with a Word Document
Adding the merge button
Now that the Word template is ready to go, create another button on the
Customer form that sends data from the form to Word. You might call it
Send Welcome Letter, as shown in Figure 1-6.
Book IX
Chapter 1
Figure 1-6:
button to
send data to
Entering the merge code
When the button is on the form, you can add the following code to this
button’s Click event procedure to send the data to the Word document:
Private Sub cmdWord_Click()
‘Declare Variables
Dim sAccessAddress As String
Dim sAccessSalutation As String
‘Build sAccessAddress
sAccessAddress = FirstName & “ “ & LastName & _
vbCrLf & Company & vbCrLf & Address1 & _
vbCrLf & City & “, “ & StateProv & “ “ & ZIPCode
‘Build sAccessSalutation
sAccessSalutation = FirstName & “ “ & LastName
‘Declare and set Word object variables
Dim Wrd As New Word.Application
Set Wrd = CreateObject(“Word.Application”)
‘Specify Path to Template
Dim sMergeDoc As String
sMergeDoc = Application.CurrentProject.Path & _
‘Open Word using template and make Word visible
Search JabSto ::

Custom Search