Solved

Access VB - avoid prompt to Select Table Mail Merge

Posted on 2014-11-12
9
309 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 49

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 49

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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 49

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 49

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

932 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

18 Experts available now in Live!

Get 1:1 Help Now