July 12, 2005 at 10:38 am
There are a number of ways to do this, but here is what I use for all my mail merges. This code is in the Word template and I happen to call it from a C# front-end but that is not required.
Sub RunMerge(strConnect As String, strParams As String)
Dim strSQL As String
strSQL = "exec dbo.rpt_Survey " & strParams
With ActiveDocument.MailMerge
.MainDocumentType = wdFormLetters
'* THIS WORKS WITH UDL or ODC FILE
.OpenDataSource Name:=strConnect, _
SQLStatement:=strSQL
.Destination = wdSendToNewDocument
.Execute Pause:=False
End With
End Sub
strConnect can reference either a UDL or ODC file and would look something like:
strConnect = "E:\Projects\MyApp\templates\myApp.udl"
strSQl references a stored procedure that takes zero to n comma separated parameters. It is important that the parameter be prefixed with "exec dbo." as shown.
robert
Viewing post 1 (of 2 total)
You must be logged in to reply to this topic. Login to reply