Results 1 to 2 of 2
  1. #1
    bellevue is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Apr 2012
    Posts
    61

    Close a Database after a Mail Merge

    I hope someone can help; furthermore, please be aware that my knowledge of the correct terminology may not be 100% accurate but I do hope that you will afford me some understanding because of that.



    I have created some code (linked to a command button on a form) which opens a word document (with mergefields) and then performs the intended mail merge: the code is below.

    However, I am in need of some help please with code to perform the following tasks:

    1) Close the "second" copy of the database (Reservations.mdb) and the Module code page once the merge is completed (it would need to entered, I think, after the red line below). To explain, when the mail merge starts, it opens a second copy of the database; I have managed to create the code to close the Main Document (BrksDednsEM.doc) but need help closing the second database.

    2) Enable the merge to take place only on the open record of the form; ie, if I am looking at record 23 and I press the command button, it merges only the data from record 23.

    I have searched various forums and googled for 3 whole days this week to try and find the solution/s but to no avail; in addition, I do appreciate that many members may wish to suggest the use of a report instead of mail merge; however, I most definitely want to use mail merge and not a report.

    Many thanks


    Function MergeIt()
    Dim objWord As Word.Document
    Set objWord = GetObject("H:\enjoy120210\CorrespondenceLetters\Ma ilMerge\BrksDednsEM.doc", "Word.Document")
    ' Make Word visible.
    objWord.Application.Visible = True
    ' Set the mail merge data source as the Northwind database.
    objWord.MailMerge.OpenDataSource _
    Name:="H:\enjoy120210\Reservations.mdb", _
    LinkToSource:=True, _
    Connection:="QUERY MasterDataSource", _
    SQLStatement:="SELECT * FROM [Customers]"
    ' Execute the mail merge.
    objWord.MailMerge.Execute
    ' Close BrksDednsEM.doc
    Word.Documents("BrksDednsEM.doc").Close (Word.WdSaveOptions.wdSaveChanges)
    ' Close Reservations.mdb

    End Function

  2. #2
    bellevue is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Apr 2012
    Posts
    61
    I may have found a simple solution to 2) from my above post but it's bringing an error message up. I've set a criteria in the query to be:

    [forms]![Reservations2]![Booking Reference]

    and this successfully brings up the query (in Datasheet View) with the data from the open record in the form.

    However, when I click on the command button on my form, it brings up a prompt box asking "Enter Parameter Value" for [forms]![Reservations2]![Booking Reference].

    When I click OK on that, it also says that it couldn't merge the main document with the data source as the fields were empty.

    Finally, my module opens up and highlights some of the code in yellow, suggesting an error ?

    Can anyone figure out what is happening or should I forget this option as a solution ?

    Click image for larger version. 

Name:	ErrorInModule.JPG 
Views:	7 
Size:	133.4 KB 
ID:	10914
    Last edited by bellevue; 01-28-2013 at 08:56 AM.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Mail Merge
    By sakhtar in forum Access
    Replies: 8
    Last Post: 09-20-2020, 09:10 AM
  2. Help with Mail Merge please ?
    By bellevue in forum Forms
    Replies: 21
    Last Post: 02-16-2013, 07:05 AM
  3. Database/Mail Merge
    By sashac in forum Access
    Replies: 0
    Last Post: 03-14-2012, 03:08 PM
  4. Mail Merge
    By DCV0204 in forum Forms
    Replies: 6
    Last Post: 12-13-2011, 09:32 AM
  5. Mail merge
    By grgerhard in forum Forms
    Replies: 0
    Last Post: 04-25-2006, 05:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums