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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Word mailMerge from SQL Server

Status
Not open for further replies.

Belcharo

Programmer
Dec 3, 2001
1
GB
I am using VBA to create a mail merge document in Word from a data source on SQL Server. Currently I have to create a pass through query in Access. How would I go about doing this directly to SQL Server?

In the code below I set up then exceute the mailMerge on the ActiveDocument.

Code:
With appwd.ActiveDocument.mailMerge
        .MainDocumentType = wdFormLetters
        .OpenDataSource Name:=strDatabase, _
                    Connection:="query qryMailMerge"
        .Destination = wdSendToNewDocument
        .Execute
End With

Where
Code:
appwd
= an reference to an open MS Word application
Code:
qryMailMerge
= the name of the pass through query in Access
Code:
strDatabase
= a string holding the full Access Database Name + Path

Idealy I could use the line
Code:
.OpenDataSource
to reference the SQL Server directly?

I have been trying to use the
Code:
Connection
argument of the
Code:
.OpenDataSource
property of the
Code:
mailMerge
object to give the path of the SQL Server or a DSN, which points to the SQL Server, but I do not know the correct syntax or if this is even possible? Another idea, would I be able to use an ADO.Connection?

Things work as they are (if a little slow). Thanks in advance to anyone who gives this some thought, I'll post a solution if I devise one in the meantime.

Best Regards

Belch

martin.Belcher@pegs .com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top