Hi 74Stag
This is how I have it set up in my db:
When user has the form open and wants to produce the letter for the record showing in the form, they click a command button which has this code as the Event Procedure for the OnClick event:
Private Sub CmdButton_Click()
DoCmd.RunCommand acCmdSaveRecord
MergeDocument "MyLetter.dot"
End Sub
The MergeDocument function is in full below and is in the Modules section of the db:
Public Sub MergeDocument(DocumentName)
' function to produce selected letters based on the qStudentMergeData query
Dim NewDocPath As String
Dim objWord As Word.Application, DocName As String
DoCmd.Hourglass True
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If objWord Is Nothing Then
Set objWord = New Word.Application
If objWord Is Nothing Then
MsgBox "MS Word is not installed on your computer"
End If
End If
On Error GoTo ErrorHandler
' set the path to the templates folder
NewDocPath = "S:\CMS\Template\" & DocumentName
DoCmd.OutputTo acOutputQuery, "qStudentMergeData", acFormatRTF, "S:\CMS\MergeDB.doc"
objWord.Documents.Add (NewDocPath)
DocName = objWord.ActiveDocument.Name
With objWord.ActiveDocument.MailMerge
.OpenDataSource "S:\CMS\MergeDB.doc"
.Destination = wdSendToNewDocument
.Execute
End With
objWord.Documents(DocName).Close False
DoCmd.Hourglass False
objWord.Visible = True
objWord.Activate
Set objWord = Nothing
Exit Sub
ErrorHandler:
DoCmd.Hourglass False
If Err.Number = 2302 Then
MsgBox "It looks like you are already using the data needed for the mail merge in another application." _
& vbCrLf & vbCrLf & "Try closing all your MS Word documents and try again.", vbInformation, "Nothing to worry about"
Else
MsgBox "It looks like we have a problem. Please write down the error number and what you were doing then call technical support." _
& vbCrLf & vbCrLf & "Error number: " & Err.Number & " and Description: " & Error, vbExclamation, "This could be serious"
End If
objWord.Visible = True
Set objWord = Nothing
End Sub
Just a thought - did you put the criteria back in the query after you had set up the template?
HTH