Automatic Access to Word Mailmerge: Sooo Close!

  • Thread starter Thread starter AckCesspool
  • Start date Start date
A

AckCesspool

Guest
Hi, I'm using some code written by someone else. Basically, I think I modified it according to my file name and path and class?

I still have several quesions:
(1) How does it know which query to use?
(2) HOW DO I ATTACH THIS TO A COMMAND BUTTON?
II pretty new at this, and only know how to get command buttons that are provided.

Public Sub MergeToWord_Click(strQuery As String, strPath As String)

Dim objWord As Object

Set objWord = GetObject("D:\Data Entry\Contact Documents\Regular.doc", Word.Application)

DoCmd.SetWarnings False
DoCmd.OpenQuery strQuery, acViewNormal
DoCmd.SetWarnings True

objWord.Documents.Open strPath, , True

With obj.Word.Documents(1).MailMerge
.Destination = 1 'Printer
.SuppressBlankLines = True
.Execute

End With

objWord.Application.Quit False

End Sub
 
Public Sub MergeToWord_Click(strQuery As String, strPath As String)

Whatever you pass in the "strQuery" variable is the Query.

Call it on a command button as follows:

Call MergeToWord("QueryNameHere","Path Here")
 
I'm still confused:{

I guess my questions are:

AS WRITTEN, SHOULD THE CODE BELOW WORK, OR
DO I NEED ADD SPECIFIC INFORMATION SUCH AS:
*FILE NAME AND PATH
*QUERY NAME (MailQuery)

Public Sub MergeToWord(strQuery As String, strPath As String)
On Error GoTo Err_MergeToWord

Dim objWord As Object

Set objWord = GetObject("D:\Data Entry\Contact Documents\Regular.doc", Word.Document)

DoCmd.SetWarnings False
DoCmd.OpenQuery strQuery, acViewNormal
DoCmd.SetWarnings True

objWord.Documents.Open strPath, , True

With obj.Word.Documents(1).MailMerge
.Destination = 1 'Printer
.SuppressBlankLines = True
.Execute

End With

objWord.Application.Quit False

End Sub

WHEN I START WITH THE FIRST LINE FOR THE COMMAND BUTTON, IT SAYS THE SYNTAX IS WRONG (MISSING IDENTIFIER). APART FROM THIS, IS WHAT IS WRITTEN BELOW CORRECT?
Private Sub cmdMergeToWord("MailQuery","D:\Data Entry")
On Error GoTo Err_cmdMergeToWord_Click

Exit_cmdMergeToWord_Click:
Exit Sub

Err_cmdMergeToWord_Click:
MsgBox Err.Description
Resume Exit_cmdMergeToWord_Click

End Sub
 

Users who are viewing this thread

Back
Top Bottom