Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with MailMerge and OpenDataSource Name

Status
Not open for further replies.

batteam

Programmer
Sep 12, 2003
374
US
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.
 
Try Name:="", Connection:=sDBPath

I believe the Name parameter is only for file system objects like an Access mdb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top