Mail Merge with Word
acCmdWordMailMerge, acCmdWindowHide
This example starts the Word Mail Merge wizard using the query passed to it.
' *********** Code Start ************
' This code was originally written by Terry Wickenden.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
Sub StartMerge(strName As String)
On Error GoTo ErrMerge
DoCmd.SelectObject acQuery, strName, True
DoCmd.RunCommand acCmdWordMailMerge
'The next 2 lines hide the database window
'Remove if database window is normally visible
DoCmd.SelectObject acQuery, strName, True
DoCmd.RunCommand acCmdWindowHide
Exit Sub
ErrMerge:
Select Case Err
Case 2046
'Command not available
MsgBox "Mail Merge is not available at this time.", vbCritical, ""Not Available"
Case 2489
'Object is not open
MsgBox strName & " must be open.", vbCritical, "Object Closed"
Case 2501
'Cancel selected in dialog box - do nothing
Case 2544
'Object does not exist
MsgBox strName & " is not a valid name.", vbCritical, "Naming Error"
Case Else
MsgBox Err.Number & ":-" & vbCrLf & Err.Description"
End Select
End Sub
' ****************** Code End ***********************