Shannon
01-17-2002, 08:39 PM
I have been trying to create a macro that will select a query, start Merge it with MS Word, than perform a macro in Word. Is this possible? Any help would be GREATLY APPRECIATED! The ending product is a letter with the export data while keeping the format. I can do it but my users will not be able to do it. That is why I would like to create a macro that will do it all. HELP PLEASE!!!
jwindon
01-19-2002, 07:30 AM
This is a task for VBA.
Goto the modules tab and post this code. Alter the name of the document to your merge doc which should have its control source set to the query or table in your database you need.
Function Merge()
Dim oApp As Object
Set oApp = CreateObject("Word.Application")
oApp.Visible = True
With oApp
'alter the path below to the doc location
.Documents.Open "C:\My Documents\somewhere.doc"
.ActiveDocument.MailMerge.Execute
'the following lines are optional
'.ActiveDocument.PrintOut
'Background:=False
' Close the document without saving changes.
'.ActiveDocument.Close
'SaveChanges:=wdDoNotSaveChanges
' Quit Microsoft Word 97 and release the object variable.
'.Quit
Set oApp = Nothing
End With
End Function
On the command button that you had set to run your macro:
Instead of RunMacro for the OnClick event, type =Merge()
Good luck!
Shannon
01-19-2002, 02:35 PM
Thank You so much! I going to give it try!
Shannon