R
Roberto
Hi, I tried to merge using a SQL statement longer than 255 ch. but the
connection fails. In Sqlstatement1 property I write the second part of the
string which contains only a simple ORDER BY statement. Only Sqlstatement1=""
is accepted. Any suggestion?
This is the code with simplified SQL statement (it doesn't work anyway):
'-----------------------------------------------
Sub trial()
Dim mydoc As Word.Application,
Dim mysql1 As String, mysql2 As String, myconnectionstring As String
Set mydoc = ActiveDocument.Application
myconnectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Password=" & Chr(34)
& Chr(34) & ";User ID=Admin;Data
Source=C:\TRIAL\mydata.mdb;Mode=Read;Extended Properties=" & Chr(34) &
Chr(34) & ";Jet OLEDBatabase Password=" & Chr(34) & Chr(34)
mysql1 = "SELECT MyTable.* FROM MyTable WHERE MyTable .SURNAME=""Smith"""
mysql2 = " ORDER BY SURNAME"
mydoc.Documents.Add , 0
mydoc.ActiveDocument.MailMerge.MainDocumentType = 3
mydoc.ActiveDocument.MailMerge.OpenDataSource Name:= _
"C:\TRIAL\mydata.mdb", ConfirmConversions:=False, ReadOnly:=False _
, LinkToSource:=True, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", WritePasswordDocument:="",
WritePasswordTemplate:= _
"", Revert:=False, Format:=0, Connection:=myconnectionstring _
, SQLStatement:=mysql1, SQLStatement1:=mysql2
mydoc.ActiveDocument.MailMerge.EditMainDocument
End Sub
'--------------------------------------
Thanks,
Roberto
connection fails. In Sqlstatement1 property I write the second part of the
string which contains only a simple ORDER BY statement. Only Sqlstatement1=""
is accepted. Any suggestion?
This is the code with simplified SQL statement (it doesn't work anyway):
'-----------------------------------------------
Sub trial()
Dim mydoc As Word.Application,
Dim mysql1 As String, mysql2 As String, myconnectionstring As String
Set mydoc = ActiveDocument.Application
myconnectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Password=" & Chr(34)
& Chr(34) & ";User ID=Admin;Data
Source=C:\TRIAL\mydata.mdb;Mode=Read;Extended Properties=" & Chr(34) &
Chr(34) & ";Jet OLEDBatabase Password=" & Chr(34) & Chr(34)
mysql1 = "SELECT MyTable.* FROM MyTable WHERE MyTable .SURNAME=""Smith"""
mysql2 = " ORDER BY SURNAME"
mydoc.Documents.Add , 0
mydoc.ActiveDocument.MailMerge.MainDocumentType = 3
mydoc.ActiveDocument.MailMerge.OpenDataSource Name:= _
"C:\TRIAL\mydata.mdb", ConfirmConversions:=False, ReadOnly:=False _
, LinkToSource:=True, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", WritePasswordDocument:="",
WritePasswordTemplate:= _
"", Revert:=False, Format:=0, Connection:=myconnectionstring _
, SQLStatement:=mysql1, SQLStatement1:=mysql2
mydoc.ActiveDocument.MailMerge.EditMainDocument
End Sub
'--------------------------------------
Thanks,
Roberto