Question : launch MS mail merge wizard via code

I have an interface that lets users build an SQL string (via text boxes, list boxes, etc.) that is used to launch forms and reports. I want to use this string to launch the MS mail merge wizard (Tools/OfficeLinks/Merge it with MS Word) and have it use my SQL string or a query def.

The command to run the wizard seems to be:

DoCmd.RunCommand (acCmdWordMailMerge)

Two problems:
1. I can't get it to work
2. It doesn't have a parameter to specify the SQL or table name.  
Any other ideas?

Answer : launch MS mail merge wizard via code

Forgive me for not testing!  Looks like I need to take a little more time with my answers.  Anyway, a few points:

1.  It will not work with an SQL string as you have discovered.  However, there are ways around this (see routine below).
2.  It is an MDE file (it used to be an MDA file in 2.0 I think.)
3.  The Wizard functions are outlined in several references; I found this information in the Access 97 Developers Handbook by Litwin/Getz.

Sub RunMailMerge(sSQL As String)
Dim db As Database
Dim qdf As QueryDef

Set db = CurrentDb
Set qdf = db.CreateQueryDef("TempQuery", sSQL)

PM_Entry (qdf.Name)

For each qdf in db.querydefs
    if qdf.name = "TempQuery" then
    DoCmd.DeleteObject acQuery, "TempQuery"
    Exit For
Next qdf
End Sub
Random Solutions  
 
programming4us programming4us