G
Guest
When I try to run the following function I get various error messages or the
system hangs:
Function MergeIt()
Dim objWord As Word.Document
Dim strConnection As String
Set objWord = GetObject("C:\MyMerge.doc", "Word.Document")
strConnection = "Driver={SQL
Server};Server=servername;Database=mydatabasename;Trusted_Connection=yes;"
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source.
objWord.MailMerge.OpenDataSource Name:="c:databasename.adp", _
Connection:=strConnection, _
SQLStatement:="SELECT * FROM tablename"
' Execute the mail merge.
objWord.MailMerge.Execute
End Function
Can anybody tell me where i'm going wrong?
system hangs:
Function MergeIt()
Dim objWord As Word.Document
Dim strConnection As String
Set objWord = GetObject("C:\MyMerge.doc", "Word.Document")
strConnection = "Driver={SQL
Server};Server=servername;Database=mydatabasename;Trusted_Connection=yes;"
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source.
objWord.MailMerge.OpenDataSource Name:="c:databasename.adp", _
Connection:=strConnection, _
SQLStatement:="SELECT * FROM tablename"
' Execute the mail merge.
objWord.MailMerge.Execute
End Function
Can anybody tell me where i'm going wrong?