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.
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.