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

Macro to automate mail merge

Status
Not open for further replies.

johnnyatyeo

Instructor
Mar 18, 2002
4
GB
I have a query called student which produces some names and addresses.I want a set of macro commands(transfer text?) that will take the output from the query,load word and load the letter I want to merge the data with.
 
I wish I could figure out a way to do this too....but I believe it is only something you can do in VBA which I don't quite have the knack for yet.
 
this is code that i use in vba the template i use is a mailmerge document. when you create your mail merge doc on the the open date source dialog box check select method box and select odbc to prevent access from loading twice
Dim mydb As Database
Set mydb = CurrentDb
If Nz(Me!Combo0, 0) < 1 Then
msgbox &quot;Please select letter&quot;, vbCritical
Exit Sub
End If
DoCmd.SetWarnings False
DoCmd.OpenQuery &quot;MTformailmerge1&quot; 'make table query
DoCmd.SetWarnings True
Dim woobj As Object, mm As Object, ret, a
Dim stDocName As String
ret = Shell(&quot;C:\Program Files\Microsoft Office\Office\winword.exe&quot;, 6)
For a = 1 To 7500
DoEvents
Next a
AppActivate &quot;Microsoft Access&quot;
Set woobj = GetObject(, &quot;Word.Application&quot;)
'woobj.fileopen &quot;f:\My Documents\registration\Sat.doc&quot;
'woobj
woobj.Documents.Add Template:=&quot;H:\My Documents\Dinner2002\&quot; & Combo0.Column(5) & &quot;.dot&quot;

Set mm = woobj.ActiveDocument.MailMerge
mm.Destination = wdSendToNewDocument
mm.Execute
woobj.PrintOut
'Dialogs(wdDialogFilePrint).Show
woobj.Documents.Close SaveChanges:=wdDoNotSaveChanges
woobj.Quit
If msgbox(&quot;Did letter print ok?&quot;, vbQuestion + vbYesNo, &quot;Print ok&quot;) = vbYes Then
mydb.Execute &quot;INSERT INTO maillings ( name, letter, [date] ) SELECT formailmerge1.id, &quot; & Me![Combo0] & &quot; AS Expr1, Now() AS Expr2 FROM formailmerge1;&quot;
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top