Question

Using Form to Select Mulitple Query to MailMerge

Asked by: eazy123

Hey there I really need help with this, I have basically made a Table which list query names as records, I haev then made the querys which are all different, I then have a form which has a combo box, the combo box looks up the values of the table which lists the queries. I have made a button on the form which I would like it to create a mail merge based on the query.

this is what I have so far on the command button:

Private Sub cmd_PrevMail_Click()

    Dim stDocName As String

    stDocName = cboSelectMailOut
    MergeIt
 
End Sub

The MergeIt part is a function which has this code:

Function MergeIt()
   Dim objWord As Word.Document
   Set objWord = GetObject("\\Stealth\DB_BACKEND\MailOutList.doc", "Word.Document")
   ' Make Word visible.
   objWord.Application.Visible = True
      objWord.MailMerge.OpenDataSource _
      name:=CurrentDb.name, _
      LinkToSource:=True, _
      Connection:="QUERY Qry_MailOuts", _
      SQLStatement:="SELECT * FROM [qry_MailOuts]"
   ' Execute the mail merge.
   objWord.MailMerge.Execute
   objWord.Close
End Function

Basically the function at the moment only selects the one query (qry_MailOuts) however I would like to make it to select the query from the combo box - the function needs to be modded so it looks up the query from the combobox.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2004-07-27 at 20:21:19ID21073718
Topic

Microsoft Access Database

Participating Experts
1
Points
500
Comments
42

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Automatic Mailmerge to Word
    Hi, this problem is bugging me, I'm not really an expert at Access but I know my way around in Access. I want that the user can do a mailmerge with just one click on the button from a form, so that he doesn't have to look the document up in word, but by clicking the button, t...
  2. Mailmerge error
    Hi In Access 2000 I open a letter with the following code DoCmd.SetWarnings False DoCmd.OpenQuery "qryMailmergeDrDelete" DoCmd.OpenQuery "qryMailmergeDrAppend" DoCmd.SetWarnings True Set objWord = GetObject("C:\PSRMS\...
  3. Password and Mailmerge
    Hi I have the following which opens a Word document.dot from within Access2000 Dim objWord As Word.Document Dim Tpath, Tremove, PathToSave Dim strFullPathAndFilename As String Dim Tpatnum T_Letters = "\\Cassey-server\Data\TempPlates\" 'T_Letters = ServerPath & ...
  4. Help w/AccessXP mailmerge code
    Hi All, I have this older code(see below) that I used for a mailmerge in another application, I'm looking to do something similar but a little different in that, this time I have a single record to merge and after the merge to the document I want to store it on a particul...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: Data-ManPosted on 2004-07-27 at 20:34:08ID: 11653115

I think you can just replace the select statement with the value of the combo box


Function MergeIt()
   Dim objWord As Word.Document
   Set objWord = GetObject("\\Stealth\DB_BACKEND\MailOutList.doc", "Word.Document")
   ' Make Word visible.
   objWord.Application.Visible = True
      objWord.MailMerge.OpenDataSource _
      name:=CurrentDb.name, _
      LinkToSource:=True, _
      Connection:="QUERY " & Me.cboQueryList
   ' Execute the mail merge.
   objWord.MailMerge.Execute
   objWord.Close
End Function

mike

 

by: eazy123Posted on 2004-07-27 at 21:04:38ID: 11653234

Nah didnt work, any other suggestions?
why did you take out the other part of the code? it needs to work with that.

 

by: Data-ManPosted on 2004-07-27 at 22:36:28ID: 11653652

I recorded a macro that did a mail merge on a query and here is what I come up with..it put the name of the query in quotes.


Function MergeIt()
   Dim objWord As Word.Document
   Set objWord = GetObject("\\Stealth\DB_BACKEND\MailOutList.doc", "Word.Document")
   ' Make Word visible.
   objWord.Application.Visible = True
      objWord.MailMerge.OpenDataSource _
      name:=CurrentDb.name, _
      LinkToSource:=True, _
      Connection:="QUERY " & me.cboQueryList , _
      SQLStatement:="SELECT * FROM '" & me.cboQueryList & "'"
   ' Execute the mail merge.
   objWord.MailMerge.Execute
   objWord.Close
End Function

Mike

 

by: eazy123Posted on 2004-07-27 at 23:31:01ID: 11653868

mmm its weird because my mail merge document still tries to use the old query which does not exist anymore....how can I make so the mail merge document doesnt have a primary datasource.

thanks

 

by: Data-ManPosted on 2004-07-28 at 09:39:09ID: 11658565

remove the mailmerge source from the document, but leave all the mail merge fields.  Your code is making it a merge document.

Mike

 

by: eazy123Posted on 2004-07-28 at 16:53:33ID: 11662582

how do i remove the mailmerge source? its office 2003 by the way?

 

by: Data-ManPosted on 2004-07-28 at 17:36:36ID: 11662778

I pulled this from the help file

Open the main document from which you want to remove the data source.
On the View menu, point to Toolbars, and then click Mail Merge.
Click Main Document Setup .
Click Normal Word document.

Mike

 

by: eazy123Posted on 2004-07-28 at 17:54:14ID: 11662838

Yeah nah it keeps asking if I want to run the SQL to run the previous query? I think its office 2003 thing?

 

by: eazy123Posted on 2004-07-28 at 17:54:27ID: 11662842

any ideas?

 

by: Data-ManPosted on 2004-07-28 at 18:08:06ID: 11662925

You might check the word area of EE

Mike

 

by: eazy123Posted on 2004-07-28 at 19:37:12ID: 11663262

Okay I found out why it did that its a security feature in word 2003, anyways I still ahve the problem of when I click on the command button it runs the code perfect the word mail merge document opens and it pops up with a box saying "confirm data source" which give you options of which data it should use. Its relly annoying and if you click cancel it goes back to access and says "Runtime error "5922" - Word was unable to open the data source" - to me this seems like it doesnt recognise that it should get its data source from the query by the name of the combobox.....? if however I select the datasource from the pop up box I can select which query I can run and it works...I have ppl working for me who would not know how to do this though so I really need the mail merge to work as I jsut click on the command and then it opens the mail merge with the query selected from the combo box? any ideas?

I changed it to normal word document but when I run the command and if I select a data source it changes from normal word document to letter?

 

by: eazy123Posted on 2004-07-28 at 19:49:41ID: 11663319

Hey DataMan, I think that your not understanding what Im trying to do - I have a form which has a combo box, the combo box gets its values from a table (the table lists all the queries I would like to have a choice of running) I select the query I want which is just text, I then click on the command button which runs the code to mail merge using the combobox text displayed... But like i said when it opens the mail merge it doesnt see that I want that query to be selected....what am I doing wrong?

 

by: Data-ManPosted on 2004-07-28 at 20:42:39ID: 11663467

I understand that...that is why I wrote the code like this

      SQLStatement:="SELECT * FROM '" & me.cboQueryList & "'"

the combo box contains the name of the query.  That is the same structure that was present when I recorded a mail merge macro based on a query.

You said your problem is that the word document is remembering the old datasource.  Is that still the problem?

Here is what I do... take your query and using transfertext export it as a word merge file.

Then in your access code open the document and then do this

    objWordApp.ActiveDocument.MailMerge.OpenDataSource Name:="Put your path here and the file name", _
        ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
        AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
        WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
        Format:=wdOpenFormatAuto, Connection:="", SQLStatement:="", SQLStatement1:=""

    'Used to refresh the data in the document
    'We have seen that word would remember the previous information
    'and if we didn't toggle you could get the data from the
    'previous letter
    objWordApp.ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
    objWordApp.ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
   
    'Send the letters to the printers merged with the records
    objWordApp.ActiveDocument.MailMerge.Destination = wdSendToPrinter
    objWordApp.ActiveDocument.MailMerge.Execute

Hope this helps...Mike

 

by: eazy123Posted on 2004-07-28 at 20:55:33ID: 11663524

because the combobox lists different queries which one do I need to export?

 

by: Data-ManPosted on 2004-07-28 at 21:06:51ID: 11663572

I'm not sure I understand your question.


but to export the query that is selected in your combo box try something like this

docmd.TransferText acExportMerge,,Me.cboQueryList,"C:\data.rtf",True

Mike

 

by: eazy123Posted on 2004-07-28 at 21:16:05ID: 11663600

well the combobox lists all the queries I have a selection of.....its pointless to export 1 query and run the command as the whole point of this question is to be able to have a choice of which query you would like to run on the mail merge - the mail merge is basically 9 labels of address - there are about 8 queries which all display diffferant addresses from different states in australia - like if i want to run the first query - it will display all those addresses in that state, the mail merge part is for labels to create labels based on the selection of which state do you want to print labels for...


I hope you understand....let me know if i can be mroe descriptive?
thanks

 

by: Data-ManPosted on 2004-07-28 at 21:31:02ID: 11663659

I don't think you are understanding what the code is doing.  The export is using the value of the combo box to do the export.  

That why the code will work no matter which query is selected.

Mike

 

by: eazy123Posted on 2004-07-28 at 21:43:01ID: 11663708

oh okay so were do I put this code?
in the same form as the combo box etc?

 

by: Data-ManPosted on 2004-07-28 at 21:49:59ID: 11663734

yes

Mike

 

by: eazy123Posted on 2004-07-28 at 22:21:40ID: 11663870

Okay but do I still have to run the other code which you first wrote??

 

by: Data-ManPosted on 2004-07-28 at 22:37:18ID: 11663927

Run the transfertext code and then this code

   objWordApp.ActiveDocument.MailMerge.OpenDataSource Name:="Put your path here and the file name", _
        ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
        AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
        WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
        Format:=wdOpenFormatAuto, Connection:="", SQLStatement:="", SQLStatement1:=""

    'Used to refresh the data in the document
    'We have seen that word would remember the previous information
    'and if we didn't toggle you could get the data from the
    'previous letter
    objWordApp.ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
    objWordApp.ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
   
    'Send the letters to the printers merged with the records
    objWordApp.ActiveDocument.MailMerge.Destination = wdSendToPrinter
    objWordApp.ActiveDocument.MailMerge.Execute

Mike

 

by: eazy123Posted on 2004-07-28 at 22:44:53ID: 11663948

were you have put the path here which path is that? for the merge doc file of the database file?

 

by: eazy123Posted on 2004-07-28 at 23:05:13ID: 11664022

Um I get an error for the export (first line) here it is:

Cannot Update - Database or object is read-only (but its not - it has all permissions)?

 

by: Data-ManPosted on 2004-07-29 at 09:22:30ID: 11668218

Can you post the code you have behind your button and the SQL of the saved queryies.

Mike

 

by: eazy123Posted on 2004-07-29 at 16:35:15ID: 11672522

Code behind Button:

Function MergeIt()

   DoCmd.TransferText acExportMerge, , Me.cboSelectMailOut, "\\Stealth\DB_BACKEND\MailOutList.rtf", True
   
   objWordApp.ActiveDocument.MailMerge.OpenDataSource Name:="\\Stealth\DB_BACKEND\MailOutList.dot", _
        ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
        AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
        WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
        Format:=wdOpenFormatAuto, Connection:="", SQLStatement:="", SQLStatement1:=""

    'Used to refresh the data in the document
    'We have seen that word would remember the previous information
    'and if we didn't toggle you could get the data from the
    'previous letter
    objWordApp.ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
    objWordApp.ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
   
    'Send the letters to the printers merged with the records
    objWordApp.ActiveDocument.MailMerge.Destination = wdSendToPrinter
    objWordApp.ActiveDocument.MailMerge.Execute
End Function

Private Sub cmd_PrevMail_Click()

    MergeIt

End Sub

Here is the SQL for the queries:

SELECT DISTINCT STORES.STORE_INDEX, STORES_CONT.FirstName, STORES_CONT.LastName, STORES.StoreName, STORES_ADDR.StoreAddr, STORES_ADDR.StoreSub, STORES_ADDR.StoreAbbrev, STORES_ADDR.StoreZip, STORES_ADDR.StoreCoun
FROM (STORES INNER JOIN STORES_ADDR ON STORES.STORE_INDEX = STORES_ADDR.STORE_INDEX) INNER JOIN STORES_CONT ON STORES.STORE_INDEX = STORES_CONT.STORE_INDEX
WHERE (((STORES_ADDR.StoreAbbrev)="ACT") AND ((STORES_ADDR.StoreCoun)="Australia") AND ((STORES_ADDR.StoreMail)=Yes) AND ((STORES_CONT.ContMail)=Yes))
ORDER BY STORES_ADDR.StoreAbbrev;

SELECT DISTINCT STORES.STORE_INDEX, STORES_CONT.FirstName, STORES_CONT.LastName, STORES.StoreName, STORES_ADDR.StoreAddr, STORES_ADDR.StoreSub, STORES_ADDR.StoreAbbrev, STORES_ADDR.StoreZip, STORES_ADDR.StoreCoun
FROM (STORES INNER JOIN STORES_ADDR ON STORES.STORE_INDEX = STORES_ADDR.STORE_INDEX) INNER JOIN STORES_CONT ON STORES.STORE_INDEX = STORES_CONT.STORE_INDEX
WHERE (((STORES_ADDR.StoreCoun)="Australia") AND ((STORES_ADDR.StoreMail)=Yes) AND ((STORES_CONT.ContMail)=Yes))
ORDER BY STORES_ADDR.StoreAbbrev;

SELECT DISTINCT STORES.STORE_INDEX, STORES_CONT.FirstName, STORES_CONT.LastName, STORES.StoreName, STORES_ADDR.StoreAddr, STORES_ADDR.StoreSub, STORES_ADDR.StoreAbbrev, STORES_ADDR.StoreZip, STORES_ADDR.StoreCoun
FROM (STORES INNER JOIN STORES_ADDR ON STORES.STORE_INDEX = STORES_ADDR.STORE_INDEX) INNER JOIN STORES_CONT ON STORES.STORE_INDEX = STORES_CONT.STORE_INDEX
WHERE (((STORES_ADDR.StoreAbbrev)="NSW") AND ((STORES_ADDR.StoreCoun)="Australia") AND ((STORES_ADDR.StoreMail)=Yes) AND ((STORES_CONT.ContMail)=Yes))
ORDER BY STORES_ADDR.StoreAbbrev;

SELECT DISTINCT STORES.STORE_INDEX, STORES_CONT.FirstName, STORES_CONT.LastName, STORES.StoreName, STORES_ADDR.StoreAddr, STORES_ADDR.StoreSub, STORES_ADDR.StoreAbbrev, STORES_ADDR.StoreZip, STORES_ADDR.StoreCoun
FROM (STORES INNER JOIN STORES_ADDR ON STORES.STORE_INDEX = STORES_ADDR.STORE_INDEX) INNER JOIN STORES_CONT ON STORES.STORE_INDEX = STORES_CONT.STORE_INDEX
WHERE (((STORES_ADDR.StoreAbbrev)="NT") AND ((STORES_ADDR.StoreCoun)="Australia") AND ((STORES_ADDR.StoreMail)=Yes) AND ((STORES_CONT.ContMail)=Yes))
ORDER BY STORES_ADDR.StoreAbbrev;

SELECT DISTINCT STORES.STORE_INDEX, STORES_CONT.FirstName, STORES_CONT.LastName, STORES.StoreName, STORES_ADDR.StoreAddr, STORES_ADDR.StoreSub, STORES_ADDR.StoreAbbrev, STORES_ADDR.StoreZip, STORES_ADDR.StoreCoun
FROM (STORES INNER JOIN STORES_ADDR ON STORES.STORE_INDEX = STORES_ADDR.STORE_INDEX) INNER JOIN STORES_CONT ON STORES.STORE_INDEX = STORES_CONT.STORE_INDEX
WHERE (((STORES_ADDR.StoreCoun)="New Zealand") AND ((STORES_ADDR.StoreMail)=Yes) AND ((STORES_CONT.ContMail)=Yes))
ORDER BY STORES_ADDR.StoreAbbrev;

SELECT DISTINCT STORES.STORE_INDEX, STORES_CONT.FirstName, STORES_CONT.LastName, STORES.StoreName, STORES_ADDR.StoreAddr, STORES_ADDR.StoreSub, STORES_ADDR.StoreAbbrev, STORES_ADDR.StoreZip, STORES_ADDR.StoreCoun
FROM (STORES INNER JOIN STORES_ADDR ON STORES.STORE_INDEX = STORES_ADDR.STORE_INDEX) INNER JOIN STORES_CONT ON STORES.STORE_INDEX = STORES_CONT.STORE_INDEX
WHERE (((STORES_ADDR.StoreAbbrev)="QLD") AND ((STORES_ADDR.StoreCoun)="Australia") AND ((STORES_ADDR.StoreMail)=Yes) AND ((STORES_CONT.ContMail)=Yes))
ORDER BY STORES_ADDR.StoreAbbrev;

SELECT DISTINCT STORES.STORE_INDEX, STORES_CONT.FirstName, STORES_CONT.LastName, STORES.StoreName, STORES_ADDR.StoreAddr, STORES_ADDR.StoreSub, STORES_ADDR.StoreAbbrev, STORES_ADDR.StoreZip, STORES_ADDR.StoreCoun
FROM (STORES INNER JOIN STORES_ADDR ON STORES.STORE_INDEX = STORES_ADDR.STORE_INDEX) INNER JOIN STORES_CONT ON STORES.STORE_INDEX = STORES_CONT.STORE_INDEX
WHERE (((STORES_ADDR.StoreAbbrev)="SA") AND ((STORES_ADDR.StoreCoun)="Australia") AND ((STORES_ADDR.StoreMail)=Yes) AND ((STORES_CONT.ContMail)=Yes))
ORDER BY STORES_ADDR.StoreAbbrev;

SELECT DISTINCT STORES.STORE_INDEX, STORES_CONT.FirstName, STORES_CONT.LastName, STORES.StoreName, STORES_ADDR.StoreAddr, STORES_ADDR.StoreSub, STORES_ADDR.StoreAbbrev, STORES_ADDR.StoreZip, STORES_ADDR.StoreCoun
FROM (STORES INNER JOIN STORES_ADDR ON STORES.STORE_INDEX = STORES_ADDR.STORE_INDEX) INNER JOIN STORES_CONT ON STORES.STORE_INDEX = STORES_CONT.STORE_INDEX
WHERE (((STORES_ADDR.StoreAbbrev)="TAS") AND ((STORES_ADDR.StoreCoun)="Australia") AND ((STORES_ADDR.StoreMail)=Yes) AND ((STORES_CONT.ContMail)=Yes))
ORDER BY STORES_ADDR.StoreAbbrev;

SELECT DISTINCT STORES.STORE_INDEX, STORES_CONT.FirstName, STORES_CONT.LastName, STORES.StoreName, STORES_ADDR.StoreAddr, STORES_ADDR.StoreSub, STORES_ADDR.StoreAbbrev, STORES_ADDR.StoreZip, STORES_ADDR.StoreCoun
FROM (STORES INNER JOIN STORES_ADDR ON STORES.STORE_INDEX = STORES_ADDR.STORE_INDEX) INNER JOIN STORES_CONT ON STORES.STORE_INDEX = STORES_CONT.STORE_INDEX
WHERE (((STORES_ADDR.StoreAbbrev)="VIC") AND ((STORES_ADDR.StoreCoun)="Australia") AND ((STORES_ADDR.StoreMail)=Yes) AND ((STORES_CONT.ContMail)=Yes))
ORDER BY STORES_ADDR.StoreAbbrev;

SELECT DISTINCT STORES.STORE_INDEX, STORES_CONT.FirstName, STORES_CONT.LastName, STORES.StoreName, STORES_ADDR.StoreAddr, STORES_ADDR.StoreSub, STORES_ADDR.StoreAbbrev, STORES_ADDR.StoreZip, STORES_ADDR.StoreCoun
FROM (STORES INNER JOIN STORES_ADDR ON STORES.STORE_INDEX = STORES_ADDR.STORE_INDEX) INNER JOIN STORES_CONT ON STORES.STORE_INDEX = STORES_CONT.STORE_INDEX
WHERE (((STORES_ADDR.StoreAbbrev)="WA") AND ((STORES_ADDR.StoreCoun)="Australia") AND ((STORES_ADDR.StoreMail)=Yes) AND ((STORES_CONT.ContMail)=Yes))
ORDER BY STORES_ADDR.StoreAbbrev;

And thats all HEHE.....anyways thanks for helping.

 

by: Data-ManPosted on 2004-07-29 at 19:50:44ID: 11673397

Put the name of the exported file in place of the datasource name.

DoCmd.TransferText acExportMerge, , Me.cboSelectMailOut, "\\Stealth\DB_BACKEND\MailOutList.rtf", True
   
   objWordApp.ActiveDocument.MailMerge.OpenDataSource Name:="\\Stealth\DB_BACKEND\MailOutList.rtf", _
       


Mike

 

by: eazy123Posted on 2004-07-29 at 20:05:02ID: 11673448

still does it - says that the database or object is read-only.... for this line:

DoCmd.TransferText acExportMerge, , Me.cboSelectMailOut, "\\Stealth\DB_BACKEND\MailOutList.rtf", True

 

by: Data-ManPosted on 2004-07-29 at 20:09:20ID: 11673460

make sure that Word or that file isn't running in the background.  Use the task manager.

Do you have full permissions to that directory?

Mike

 

by: eazy123Posted on 2004-08-01 at 16:45:48ID: 11690029

yeah i have full permissions and it wasnt running in the background....Im thinking of scraping the whole idea and just making one document merge for each query? as it looks thats the only way it will work!!!

let me know ur thoughts

 

by: Data-ManPosted on 2004-08-01 at 19:51:32ID: 11690652

The code I showed you, is what I use.  

I export the records to a word merge file
I open word in VBA (from Access)
Open the word file (the one with the merge field) - no datasource
Tell the document it is a mail merge and the data source
Merge to printer

I've been doing it for years....no problems.

Are you sure that your word document doesn't have a data source?  It should only contain merge fields.

Mike

 

by: eazy123Posted on 2004-08-01 at 19:55:04ID: 11690665

can I send you the files?
so you can try it?
i am using 2003 version though

 

by: Data-ManPosted on 2004-08-01 at 20:21:04ID: 11690718

no problem.....I'll post the solution here for all to see.

Zip the db and the word document together....michael.stalford@cox.net

Mike

 

by: eazy123Posted on 2004-08-01 at 20:25:29ID: 11690730

okay will do now.
 thanks

 

by: Data-ManPosted on 2004-08-01 at 23:41:05ID: 11691239

Here is all the code behind the form.  You were exporting the data to the same file name as the word document that contained your merge fields.  I changed the export file name.

Option Compare Database
Option Explicit
Public Sub sbMergeIt()

    Dim strPath As String

    'Create the object variables need
    'Make sure there is a reference to MS Word
    Dim objWordDoc As Word.Document
    Dim objWordApp As Word.Application

    'Set the variable that holds the path to the files used in the procedure
    'Change it to match your path \\Stealth\DB_BACKEND\
    'strPath = "C:\Documents and Settings\Administrator\My Documents\Access Databases\"
    strPath = "\\Stealth\DB_BACKEND\"

    'Export the data from the selected query.  Notice the file name is not the same as the word document we are trying to merge it with
    DoCmd.TransferText acExportMerge, , Me.cboSelectMailOut, strPath & "MailOutMergeData.txt", True
   
   'Create our object variable
    Set objWordApp = CreateObject("Word.Application")
   
    'Open the word document
    Set objWordDoc = objWordApp.Documents.Open(strPath & "MailOutList.doc")
   
   
    objWordApp.ActiveDocument.MailMerge.OpenDataSource Name:=strPath & "MailOutMergeData.txt", _
        ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
        AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
        WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
        Format:=wdOpenFormatAuto, Connection:="", SQLStatement:="", SQLStatement1:=""

    'Used to refresh the data in the document
    'We have seen that word would remember the previous information
    'and if we didn't toggle you could get the data from the
    'previous letter
    objWordApp.ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
    objWordApp.ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
   
    'Send the letters to the printers merged with the records
    objWordApp.ActiveDocument.MailMerge.Destination = wdSendToPrinter
   
    'If you want it to be automatic, then uncomment the next 3 lines and comment the visible line
    objWordApp.Visible = True
    'objWordApp.ActiveDocument.MailMerge.Execute
    'objWordApp.Quit wdDoNotSaveChanges
    'Set objWordApp = Nothing
   
End Sub

Private Sub cmd_PrevMail_Click()

    Call sbMergeIt
    MsgBox "List exported to printer"
   
End Sub

Private Sub cmd_Close_Click()
    Quit
End Sub

 

by: eazy123Posted on 2004-08-01 at 23:53:26ID: 11691272

Hi yeah it says the list exported to printer but nothing prints? whats meant to happened once I click the command button?

 

by: Data-ManPosted on 2004-08-01 at 23:58:35ID: 11691287

If the visible line of code near the end the end of the procedure is uncommented, then it will leave you with MS Word open.

If you comment out the visible and uncomment the other three lines of code, it will send the merged file (labels) to the printer.  Make sure you have labels in the printer.

Mike

 

by: eazy123Posted on 2004-08-02 at 00:03:12ID: 11691303

actually I made it work - i just uncomented the 3 lines to do it automatic.....anyway of making it so it pops up with a pritner selection before it prints?

 

by: Data-ManPosted on 2004-08-02 at 00:04:06ID: 11691312

:-).....Mike

 

by: eazy123Posted on 2004-08-02 at 00:26:57ID: 11691401

does it use teh default printer?

 

by: Data-ManPosted on 2004-08-02 at 00:32:27ID: 11691423

yes..Mike

 

by: eazy123Posted on 2004-08-02 at 00:35:58ID: 11691434

anyways of making it popup with the printer pop up box to select which printer you want to use?

 

by: Data-ManPosted on 2004-08-02 at 00:39:50ID: 11691446

not that I know of off the the top of my head.

You may want to close out this question and post that one along with the code and see what people come up with.

Mike

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...