Mail Merge

dsomers

Registered User.
Local time
Today, 23:11
Joined
Nov 13, 2003
Messages
131
Need help with mail merge

Hello all! I'm trying to do a mail merge with a word document in my real estate program in Access. I searched the forums and found a link to support on Microsoft's website for how to code in automatically doing a mail merge in word. However, when I try to do the mail merge, Word locks up and prints nothing. Here is the function I'm using to do the mail merge:

Private Function MergeIt()

Dim objWord As Word.Document
Set objWord = GetObject("G:\Eviction Notice - 11th.doc", "Word.Document")

' Make Word invisible
objWord.Application.Visible = True

' Set the mail merge data source as the database
objWord.MailMerge.OpenDataSource Name:="G:\temp6\FPMLLCNEW_SB.mdb", LinkToSource:=True, Connection:="TABLE tblTempEvictionNotice", SQLStatement:="Select * from tblTempEvictionNotice where ((tblTempEvictionNotice.Payment)=True)"

objWord.MailMerge.Destination = wdSendToNewDocument
objWord.MailMerge.Execute

' The following line must follow the Execute statement because the
' PrintBackground property is available only when a document window is
' active. Without this line of code, the function will end before Word
' can print the merged document.

objWord.Application.Options.PrintBackground = False
objWord.Application.ActiveDocument.PrintOut

objWord.Application.ActiveDocument.Close
objWord.Application.Quit savechanges:=wdDoNotSaveChanges
Set objWord = Nothing

End Function

I also have the program up on http://briefcase.yahoo.com. Username is davidinncsu. Pass is ncsuwon. Its in the zip archive fpmllcv26.zip. The document that I'm doing the mail merge with is 'Eviction Notice - 11th.doc'.

If someone could take a look and help me figure out whats going on, I'd appreciate it.

Thanks!
David Somers

EDIT: Yeah, I know Visible is set to True when I have a comment saying to set it invisible. I set it to true for testing purposes. :)
 
I would suggest skipping the mail-merge entirely. Create a report that looks like your doc, and use the docmd.sendto (if you're using outlook) command to send the email. I generally try to stay away from using external items (docs, xls) if I can help it.
 
Oops, Docmd.SendObject
 
I would like to save creating a report as a last resort for this document. I really would like to get this mail merge working correctly because I would like to as my next step select a tenant and have it print their lease with all the information filled in. The lease that I have is in doc format and is pretty complicated as far as spacing to create using a report.

So, if you or anybody could please help me get this mail merge working correctly, I would really appreciate it.

Thanks!
David Somers
 
Well, I've been working most of the day trying to get this mail merge to work right and I can't get it. So, my question now is if there is a way to import my Word documents into Access and have them imported into a report?

Thanks!
David Somers
 
Copy and paste - format to look like you want. Then add your fields and it should be that easy. If you really wanted to (or if the documents are constantly changing) you could add the document data into a table for easy edits.
 
I have an application that does a merge to Word. The user can select the document from a combo and then merge to that document. The key to this approach working is that the Word Doc is configured to use a datafile called mergedata.doc, and that the Word doc and the merge file are copied into a folder that has otherwise been emptied. Here's the code with comments
Code:
Private Sub Writelet_Click()
On Error GoTo Err_Writelet_Click
'Check for document selected
     If IsNull(DocName.Column(2, DocName.ItemsSelected)) Then
     MsgBox "No contract selected"
     GoTo Exit_Writelet_Click:
     End If
'Create variables for document name and document path
    Docpath = DocName.Column(2, DocName.ItemsSelected)
    Doctitle = DocName.Column(1, DocName.ItemsSelected)
    'MsgBox Docpath
'Empty workfolder, copy template and source file to workfolder
    FileCopy (ParentDir & "dummy.txt"), (WorkFolder & "dummy.txt")
    Kill (WorkFolder & "*.*")
    FileCopy (ParentDir & "DocMaster\" & Docpath), (WorkFolder & Docpath)
    'Create mailmerge file
    Datafile = WorkFolder & "mergedata.doc"
    'MsgBox Datafile
    DoCmd.OpenQuery "Letcontract", acNormal, acReadOnly
    DoCmd.TransferText acExportMerge, "", "Letcontract", Datafile, False, ""
    DoCmd.close acQuery, "Letcontract"
'Open word and load file
    Dim objword As Word.Application
    Set objword = New Word.Application
    objword.Visible = True
    objword.Activate
    objword.Documents.Open (WorkFolder & Docpath)


Exit_Writelet_Click:
    Exit Sub

Err_Writelet_Click:
    MsgBox Err.Description
    Resume Exit_Writelet_Click
    
End Sub
 

Users who are viewing this thread

Back
Top Bottom