Hi
I have posted this on Forms but upon reflection I believe that it may be more appropriate here:
I have a form that is made up of one main form and 4 subforms. I want to use the recordset data on the screen in Word and I am not sure how to collect it as it is from several sources.
The code that I have works well with one record source and I'm unsure how to modify it to cope with more than one. (encl)
I intend to use it in a mail merge document.
Are there any other issues that I should be considering?
Thanks in advance.
Steven811 - novice
Function MergeIt()
Dim objWord As Word.Document
Dim strSQL As String
Dim strSQL2 As String
Set objWord = GetObject("C:\MyMerge.doc", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
strSQL2 = Forms("forCustomerDetails").Form.Controls("CompanyName").Value
strSQL = "SELECT * FROM [tblCustomerDetails]WHERE [tblCustomerDetails.CompanyName] = '" & strSQL2 & "'"
'MsgBox (strSQL)
objWord.MailMerge.OpenDataSource _
Name:="C:\Documents and Settings\Admin\Desktop\EC_EX\DbFiles\ec-ex.mdb", _
LinkToSource:=True, _
Connection:="TABLE tblCustomerDetails", _
SQLStatement:=strSQL
' Execute the mail merge.
objWord.MailMerge.Execute
objWord.Close
End Function
I have posted this on Forms but upon reflection I believe that it may be more appropriate here:
I have a form that is made up of one main form and 4 subforms. I want to use the recordset data on the screen in Word and I am not sure how to collect it as it is from several sources.
The code that I have works well with one record source and I'm unsure how to modify it to cope with more than one. (encl)
I intend to use it in a mail merge document.
Are there any other issues that I should be considering?
Thanks in advance.
Steven811 - novice
Function MergeIt()
Dim objWord As Word.Document
Dim strSQL As String
Dim strSQL2 As String
Set objWord = GetObject("C:\MyMerge.doc", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
strSQL2 = Forms("forCustomerDetails").Form.Controls("CompanyName").Value
strSQL = "SELECT * FROM [tblCustomerDetails]WHERE [tblCustomerDetails.CompanyName] = '" & strSQL2 & "'"
'MsgBox (strSQL)
objWord.MailMerge.OpenDataSource _
Name:="C:\Documents and Settings\Admin\Desktop\EC_EX\DbFiles\ec-ex.mdb", _
LinkToSource:=True, _
Connection:="TABLE tblCustomerDetails", _
SQLStatement:=strSQL
' Execute the mail merge.
objWord.MailMerge.Execute
objWord.Close
End Function