Link to home
Start Free TrialLog in
Avatar of WTsuk
WTsuk

asked on

Access VB - avoid prompt to Select Table Mail Merge

Access 2007 VB print Mail Merge Word 2007.  It prompt to Select Table.  I want to know VB auto print without Prompt Select Table.

Private Sub PrintMMword()
Dim templateName As String, tempRoot As String
tempRoot = "C:\wordtech\mailmerge\"
templateName = tempRoot & "msseq1.docx"
Dim objDoc As Word.Document
Dim objWord As New Word.Application
Dim outputFileName As String
outputFileName = CurrentProject.Path & "\Qmail.xls"

With objWord
    .DisplayAlerts = False
    .Application.Visible = False
    Set objDoc = objWord.Documents.Open(templateName)
    With objDoc.MailMerge
        .MainDocumentType = wdFormLetters
        .OpenDataSource Name:=outputFileName, LinkToSource:=True
        .Destination = wdSendToPrinter
        .Execute
    End With
    .Quit SaveChanges:=False
End With
Set objWord = Nothing
Set objDoc = Nothing
End Sub
Avatar of Rgonzo1971
Rgonzo1971

Hi,

pls try

Private Sub PrintMMword()
Dim templateName As String, tempRoot As String
tempRoot = "C:\wordtech\mailmerge\"
templateName = tempRoot & "msseq1.docx"
Dim objDoc As Word.Document
Dim objWord As New Word.Application
Dim outputFileName As String
outputFileName = CurrentProject.Path & "\Qmail.xls"

With objWord
    .DisplayAlerts = False
    .Application.Visible = False
    Set objDoc = objWord.Documents.Open(templateName)
    With objDoc.MailMerge
        .MainDocumentType = wdFormLetters
        .OpenDataSource Name:=outputFileName, _
             Connection:="TABLE YourTable"
        .Destination = wdSendToPrinter
        .Execute
    End With
    .Quit SaveChanges:=False
End With
Set objWord = Nothing
Set objDoc = Nothing
End Sub

Open in new window

Regards
Avatar of WTsuk

ASKER

I still getting Prompt Table Selection.  i have to click OK on the Prompt Table Selection.
Have you changed YourTable with your Source Table or Query
Avatar of WTsuk

ASKER

There are two table names on prompt box.  MMout and MMout$
I changed Table name and still got Prompt box.
Connection:="TABLE MMout"
is MMout a query or a Table

if a query try "VIEW MMout"
Avatar of WTsuk

ASKER

file is excel file.  Qmail.xls.  It is exported from access table (the table name is MMout).  MMout is the Sheet name on Qmail.xls.  When I open Qmail.xls, I only see MMout.  I do not see MMout$.  But on Merge Document Prompt box shows two table name.  MMout and MMout$.
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of WTsuk

ASKER

Thank you.  It printed without Prompt box.
Avatar of WTsuk

ASKER

Thank you very much.  It saved a lot of time.