[AccessD] Mail Merge - Verifying user is satisfied and comple ted the merge

Brett Barabash BBarabash at TappeConstruction.com
Tue Jan 20 14:21:55 CST 2004


John, 
I've never used the built-in Mail Merge in Access so I can't help you there,
but here's what I was able to come up with using OLE automation.  This
requires a reference to your Word object library:

Private Const cTemplate = "c:\temp\template.doc"
Private mstrDocName As String
Private WithEvents mobjWord As Word.Application

Private Sub cmdMerge_Click()

    'Create a new instance of Word
    If mobjWord Is Nothing Then
        Set mobjWord = New Word.Application
    End If
    
    'Open the template document and merge to new document
    mobjWord.Documents.Open cTemplate 
    
    With mobjWord.Documents(cTemplate).MailMerge
        .Destination = wdSendToNewDocument
        .Execute
    End With
    
    'Keep track of the newly created document name and close the template
    With mobjWord
        mstrDocName = .ActiveDocument.Name
        .Documents(cTemplate).Close False
        .Visible = True
    End With

End Sub

Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
    
    'Cleanup the existing copy of Word
    mobjWord.Quit False
    Set mobjWord = Nothing
    
End Sub

Private Sub mobjWord_DocumentBeforeClose(ByVal Doc As Word.Document, Cancel
As Boolean)
    
    'User is closing document, check to see if it's the one we created
    If Doc.Name = mstrDocName Then
        'Hide Word application so our Access app can gain focus
        mobjWord.Visible = False
        
        If MsgBox("Save changes?", vbYesNo) = vbYes Then
            Doc.SaveAs "c:\temp\test.doc"
        Else
            'Close without saving
            Doc.Close False
        End If
    End If

End Sub

=====

I am attempting to set up a system where one group of people "order"
merged documents, and another set of users then print those ordered
documents, QA and mail them out.  The users that order the documents
will do the mail merge (on their local machine), with the document
opened and visible to them after the merge.  The user can then edit the
document (add sentences / paragraphs etc), scan that the merged data is
correct etc.  

If they are happy then I need to save the merged document out to a
common location on the network with the doc name modified to include the
initials of the person ordering the document, the date, the claim number
that the doc is about etc.  If the user is not happy, I need to just
delete the
document(s) on the local drive.

My question is, how do I stop processing as I open the document so that
I can then ask the user if it all worked satisfactorily after they close
the document.  Is it possible to "open the document MODAL (so to speak)
where they are in Word, can edit and do whatever, but they have to close
Word to get back to Access?  

How do you guys handle this stuff.

John W. Colby
The DIS database guy


--------------------------------------------------------------------------------------------------------------------
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom
they are addressed.
If you have received this email in error please notify the
originator of the message. This footer also confirms that this
email message has been scanned for the presence of computer viruses.

Any views expressed in this message are those of the individual
sender, except where the sender specifies and with authority,
states them to be the views of Tappe Construction Co.

Scanning of this message and addition of this footer is performed
by SurfControl E-mail Filter software in conjunction with 
virus detection software.



More information about the AccessD mailing list