R
Robert
I have a mailmerge document in Word 2002 that uses a SQL query against
a SQL Server database. The relevant code is as follows:
With ActiveDocument.MailMerge
.MainDocumentType = wdFormLetters
.OpenDataSource Name:=strConnectString, _
SQLStatement:=strSQL
.Destination = wdSendToNewDocument
.Execute Pause:=False
End With
The strConnectString variable is the full path to an .ODC file (thanks
to Peter Jamieson for that).
The mail merge was running fine until I wanted to add an ORDER BY
clause to the SQL string. That pushed it over the 255 character limit,
so I put the clause in strSQL1 and changed the code to this:
.OpenDataSource Name:=strConnectString, _
SQLStatement:=strSQL, SQLStatement1:=strSQL1
Unfortunately the code would no longer run. No matter how I construct
the two SQL segments, if I use the SQLStatement1 parameter for
anything I always get the error message "Word could not open the data
source."
I've tested the combined SQL statement to be sure it's valid, so my
only conclusion is that for some reason you can't break up your SQL
into two pieces the way the documentation claims you can.
Does anyone dealt with this issue at all?
Robert
a SQL Server database. The relevant code is as follows:
With ActiveDocument.MailMerge
.MainDocumentType = wdFormLetters
.OpenDataSource Name:=strConnectString, _
SQLStatement:=strSQL
.Destination = wdSendToNewDocument
.Execute Pause:=False
End With
The strConnectString variable is the full path to an .ODC file (thanks
to Peter Jamieson for that).
The mail merge was running fine until I wanted to add an ORDER BY
clause to the SQL string. That pushed it over the 255 character limit,
so I put the clause in strSQL1 and changed the code to this:
.OpenDataSource Name:=strConnectString, _
SQLStatement:=strSQL, SQLStatement1:=strSQL1
Unfortunately the code would no longer run. No matter how I construct
the two SQL segments, if I use the SQLStatement1 parameter for
anything I always get the error message "Word could not open the data
source."
I've tested the combined SQL statement to be sure it's valid, so my
only conclusion is that for some reason you can't break up your SQL
into two pieces the way the documentation claims you can.
Does anyone dealt with this issue at all?
Robert