Solved

Access VB - avoid prompt to Select Table Mail Merge

Posted on 2014-11-12
9
292 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
  • 5
  • 4
9 Comments
 
LVL 48

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 48

Expert Comment

by:Rgonzo1971
ID: 40439688
Have you changed YourTable with your Source Table or Query
0
 

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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 48

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 48

Accepted Solution

by:
Rgonzo1971 earned 500 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now