ordendelfai
Technical User
This is my last question, and I am squared away with this project (yay!).
Using the below code, the last problem I have run into is when there are no matching records a really nasty error message pops up from word and from access (asking to debug). I need to find a way to either make the merge still happen and just not merge any data, or a quick and easy line of code that stops the merge from occuring with a custom message box if no records are returned in the query the merge is looking at for data.
Thanks!! =D
Joel
---------------------------code-----------------------------
Public Function MergeItBlankFaxPrint()
Dim objWord As Word.Document
Set objWord = GetObject("C:\MyDB\Templates\ExternalCorrespondence\BlankFax.doc", "Word.Document"
' Make Word visible.
objWord.Application.DisplayAlerts = False
objWord.Application.Visible = True
' Set the mail merge data source as the Access database.
objWord.MailMerge.OpenDataSource _
Name:="C:\MyDB\MyDB.mdb", _
LinkToSource:=False, _
Connection:="QUERY qryMailMergeBlankFax"
' Execute the mail merge.
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
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Function
Using the below code, the last problem I have run into is when there are no matching records a really nasty error message pops up from word and from access (asking to debug). I need to find a way to either make the merge still happen and just not merge any data, or a quick and easy line of code that stops the merge from occuring with a custom message box if no records are returned in the query the merge is looking at for data.
Thanks!! =D
Joel
---------------------------code-----------------------------
Public Function MergeItBlankFaxPrint()
Dim objWord As Word.Document
Set objWord = GetObject("C:\MyDB\Templates\ExternalCorrespondence\BlankFax.doc", "Word.Document"
' Make Word visible.
objWord.Application.DisplayAlerts = False
objWord.Application.Visible = True
' Set the mail merge data source as the Access database.
objWord.MailMerge.OpenDataSource _
Name:="C:\MyDB\MyDB.mdb", _
LinkToSource:=False, _
Connection:="QUERY qryMailMergeBlankFax"
' Execute the mail merge.
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
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Function