Hi Guys
I am writing the following code to print off the word letters but anyhow its saying Invalid merge field, "You want to remove it or replace it"
But I am using right field names in the document. I have checked many times and they are right so not sure why its giving me invalid merge field message every time I run the code.
Private Sub CmdPrint_Click()
Application.DisplayAlerts = False
Call Merge_123
Application.DisplayAlerts = True
MsgBox "The letters have been printed off."
End Sub
Sub Merge_123()
MsgBox "Hello"
strworkbookname = "J:\WilliamsLea-AIMM\Critical Document Handling\ODH System.mdb"
With CreateObject("Word.Application").Documents.Add("C:\Documents and Settings\kaura2\Desktop\Reference.doc").MailMerge
.MainDocumentType = 0
.Destination = 1
.OpenDataSource _
Name:=strworkbookname, _
AddToRecentFiles:=False, _
Revert:=False, _
Format:=wdOpenFormatAuto, _
Connection:="Data Source=" & strworkbookname & ";Mode=Read", _
sqlstatement:="SELECT * FROM `tblmaster` where Printpoolno='" & ComboBox2 & "'"
.Execute
.Parent.Close 0
End With
MsgBox "The letters have been printed off"
End Sub
Please see attached the word document as well. In the table there are following fields:
Username,Surname,PolicyNo,Printpoolno,QADD,QAMM,QAYYYY
I hope anyone can help me in this.
Thanks
Bookmarks