?
Solved

Access VB - avoid prompt to Select Table Mail Merge

Posted on 2014-11-12
9
Medium Priority
?
382 Views
Last Modified: 2014-11-13
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
0
Comment
Question by:WTsuk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 40439253
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
0
 

Author Comment

by:WTsuk
ID: 40439686
I still getting Prompt Table Selection.  i have to click OK on the Prompt Table Selection.
0
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 40439688
Have you changed YourTable with your Source Table or Query
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:WTsuk
ID: 40439728
There are two table names on prompt box.  MMout and MMout$
I changed Table name and still got Prompt box.
Connection:="TABLE MMout"
0
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 40440109
is MMout a query or a Table

if a query try "VIEW MMout"
0
 

Author Comment

by:WTsuk
ID: 40440133
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$.
0
 
LVL 52

Accepted Solution

by:
Rgonzo1971 earned 2000 total points
ID: 40440435
Sorry I read Access

pls try

.OpenDataSource Name:=outputFileName , SQLStatement:="SELECT * FROM `MMout$`"
0
 

Author Comment

by:WTsuk
ID: 40440455
Thank you.  It printed without Prompt box.
0
 

Author Closing Comment

by:WTsuk
ID: 40440458
Thank you very much.  It saved a lot of time.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question