Mail Merge

  • Just moving over from access to SQL. In my old access dB I had a mail merge to MS Word, I am now using a ADP as my front end can anyone help me in how i can get a mail merge to work in this format.

  • 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 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply