I am tryhing to open a Word document with MailMerge behind an Access 2007 (project) form, with data stored in SQL tables. I am having trouble setting the datasource, which is a temp table in SQL. My code is:
sDBPath = "Provider=SQLOLEDB.1;Server=XXXXXXXXXX0118;Database=MyDBName;uid=sa;PWD=;"
Set wrdApp = New Word.Application
Set Doc = wrdApp.Documents.Add(conTemplate)
With Doc.MailMerge
.OpenDataSource Name:=sDBPath, _
SQLStatement:="SELECT * from dbo.MyTableName"
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
etc....
etc....
My code always hangs the program at the .OpenDataSource command. I have tried numerous combinations of variables, etc, using 'LinkToSource', etc. but in the and nothing seems to work. An exhaustive search on the internet shows plenty of examples but all give the same unsuccessful result. All my variables are properly dimmed. Any help would be appreciated.
sDBPath = "Provider=SQLOLEDB.1;Server=XXXXXXXXXX0118;Database=MyDBName;uid=sa;PWD=;"
Set wrdApp = New Word.Application
Set Doc = wrdApp.Documents.Add(conTemplate)
With Doc.MailMerge
.OpenDataSource Name:=sDBPath, _
SQLStatement:="SELECT * from dbo.MyTableName"
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
etc....
etc....
My code always hangs the program at the .OpenDataSource command. I have tried numerous combinations of variables, etc, using 'LinkToSource', etc. but in the and nothing seems to work. An exhaustive search on the internet shows plenty of examples but all give the same unsuccessful result. All my variables are properly dimmed. Any help would be appreciated.