I am trying to use a form button to open a Word MailMerge document and populate it's Merge fields with the data from only the record showing on the form. I generated the following code to do this by recording a macro in Word.
ActiveDocument.MailMerge.OpenDataSource Name:= _
"C:\StudentServices\StudentServices8_28.mdb", ConfirmConversions:=False, _
ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto, _
Connection:= _
"Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=C:\StudentServices\StudentServices8_28.mdb;Mode=Read;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDBatabase Password="""";Jet OLEDB:Engine Type=5;Jet OLEDB" _
, SQLStatement:="SELECT * FROM `tblStudents`", SQLStatement1:="", _
SubType:=wdMergeSubTypeAccess
This code works to open all records from tblStudents as shown in the SQLStatement:= . . . argument of the function. However, when I add a WHERE clause to the SQL I get the following error: "Remote Server not found or Remote Server unavailable"
Any idea why this is error and what to do about it? Thanks.
ActiveDocument.MailMerge.OpenDataSource Name:= _
"C:\StudentServices\StudentServices8_28.mdb", ConfirmConversions:=False, _
ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto, _
Connection:= _
"Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=C:\StudentServices\StudentServices8_28.mdb;Mode=Read;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDBatabase Password="""";Jet OLEDB:Engine Type=5;Jet OLEDB" _
, SQLStatement:="SELECT * FROM `tblStudents`", SQLStatement1:="", _
SubType:=wdMergeSubTypeAccess
This code works to open all records from tblStudents as shown in the SQLStatement:= . . . argument of the function. However, when I add a WHERE clause to the SQL I get the following error: "Remote Server not found or Remote Server unavailable"
Any idea why this is error and what to do about it? Thanks.