Auto-Merge from Access to Word

DaveN1996

New member
Local time
Today, 14:48
Joined
Feb 18, 2011
Messages
2
Hello!

I currently have an access 2010 database that I have tied to word on several forms for word merge purposes. Currently I have a button on the form that opens into the word doc, but that's it...

I've seen in other versions where you can code the button to open the document in word and THEN merge it (which, this is for end users that would appreciate having 1 less button to click).

Any help would be greatly appreciated
 
DaveN,

This will be a little late for you I'm guessing but I have done the following on code, to be added to a button 'on click'. the word template has been set up for merging from the source db with relevent fields in the correct place.

Code:
Private Sub Cmd_merge_to_word_Click()
Dim strBusID As String
Dim strContID As String
Dim wdApp As New Word.Application
Dim wdMMDoc As Word.Document
' Get the Info for the where statement on the SQLStatement
    strBusID = "[3rdPartyBusinessID] = " & [3rdPartyBusinessID] & ""
    strContID = "[3rdPartyContactID] = " & [3rdPartyContactID] & ""
    
' Open the merge document and give it a name!
Set wdMMDoc = wdApp.Documents.Add("c:\Access\Merge.dotx")
    wdApp.Visible = True
' Connect to datasource and run sqlstatement to pick the info from the form
    wdApp.ActiveDocument.MailMerge.OpenDataSource _
        Name:=Application.CurrentProject.FullName, _
        OpenExclusive:=False, _
        LinkToSource:=True, _
        Connection:= _
        "Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=c:\Access\DBv2.accdb;Mode=Read;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Engine Type=6;Jet OLEDB:Database Locking Mode=0;Jet" _
        , SQLStatement:="SELECT * FROM `qry_3rd_P_address_merge` Where " & strBusID & " And " & strContID
' Run the merge
    wdMMDoc.MailMerge.Execute
' Close the Merge Document
    wdMMDoc.Close False
    wdApp.Visible = True
' Bring the merged letter to the front
    wdApp.Activate
' tidy up
    Set wdApp = Nothing
    Set wdMMDoc = Nothing
End Sub

Hope it helps.
 
Hi,
I think I can use this in my db.
Could someone explain me how to use this code?

Thanks
 

Users who are viewing this thread

Back
Top Bottom