C
cc900630
Hi, I am trying to write vba program that will work on Word 2000 & 2002
clients and connect to SQL 2000 to produce a batch of invoices using
mailmerge automation.
I am having problems with the connection.It gives a runtime error 5174,
"This file could not be found", although I have tested the code and
both the connection string and SQL works fine (see below). Any help /
alternatives appreciated.
thanks
hals_left
Sub MailMergeTest()
Dim strConn, strSQL, objRS, strResult
Dim objConn As New ADODB.Connection
' SQL Server 2K on local machine integrated security
strConn = "Provider=sqloledb;" & _
"Data Source=(local);" & _
"Initial Catalog=pubs;" & _
"Integrated Security=SSPI"
strSQL = "Select stor_id, stor_name from stores"
' ~~~~~~~~ Test the connection manually
objConn.Open strConn
Set objRS = objConn.Execute(strSQL)
While Not objRS.EOF
strResult = strResult & objRS(0) & "-" & objRS(1) & vbCrLf
objRS.MoveNext
Wend
MsgBox strResult
objConn.Close
Set objConn = Nothing
' ~~~~~~~~~ Now mailmerge - doesnt work
ActiveDocument.MailMerge.OpenDataSource strConn, , , , , , , , , ,
, , , strSQL
ActiveDocument.MailMerge.Execute
End Sub
clients and connect to SQL 2000 to produce a batch of invoices using
mailmerge automation.
I am having problems with the connection.It gives a runtime error 5174,
"This file could not be found", although I have tested the code and
both the connection string and SQL works fine (see below). Any help /
alternatives appreciated.
thanks
hals_left
Sub MailMergeTest()
Dim strConn, strSQL, objRS, strResult
Dim objConn As New ADODB.Connection
' SQL Server 2K on local machine integrated security
strConn = "Provider=sqloledb;" & _
"Data Source=(local);" & _
"Initial Catalog=pubs;" & _
"Integrated Security=SSPI"
strSQL = "Select stor_id, stor_name from stores"
' ~~~~~~~~ Test the connection manually
objConn.Open strConn
Set objRS = objConn.Execute(strSQL)
While Not objRS.EOF
strResult = strResult & objRS(0) & "-" & objRS(1) & vbCrLf
objRS.MoveNext
Wend
MsgBox strResult
objConn.Close
Set objConn = Nothing
' ~~~~~~~~~ Now mailmerge - doesnt work
ActiveDocument.MailMerge.OpenDataSource strConn, , , , , , , , , ,
, , , strSQL
ActiveDocument.MailMerge.Execute
End Sub