Solved

Access VB - avoid prompt to Select Table Mail Merge

Posted on 2014-11-12
9
328 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 50

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 50

Expert Comment

by:Rgonzo1971
ID: 40439688
Have you changed YourTable with your Source Table or Query
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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 50

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 50

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

856 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