Merge Query with Microsoft Word Automation

sashapixie

Board Regular
Joined
Aug 29, 2013
Messages
71
Office Version
  1. 365
Platform
  1. Windows
Hell All

I have a word document and an access query that I want to be merged as an automation by the user clicking on a toggle option button.

The following code opens the word document:

Sub MergeStaffAddresses()


Dim Wrd As Word.Application
Set Wrd = CreateObject("Word.Application")
Dim WordDoc As String

DoCmd.OpenQuery "Staff Addresses", acViewNormal, acEdit
DoCmd.ApplyFilter "StaffAddresses", "[Type]=""Staff""", ""
DoCmd.Save
'Path to the word document
WordDoc = "C:\Users\CherylHughes\Documents\Database\Address_Labels.docx"

Wrd.Documents.Open WordDoc
Wrd.Visible = True

End Sub

However being new to vba and struggling to get my head round it I am failing to link the query once the word document if open. All the code I find online is 1. Very daunting and 2. doesn't work.

I thought about running a macro in the word document to perform the mail merge but when the document opens the code has disappeared from the VBE.

My other option was to using the macro builder to get to the point of commanding a mail merge but then I get stuck at the point of the mail merge pop up box asking where I want my data source to come from.

Basically I want to click the toggle button and use vba to run the mail merge, and vica versa when the user clicks the other toggle button.

Toggle buttons are "Staff" "Operative" "All".

At the moment the toggle button opens the query and filters by type for the chosen button.

Fingers crossed someone can help as I have wasted an entire weekend on this and so far with zero results :(
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Forum statistics

Threads
1,221,905
Messages
6,162,768
Members
451,786
Latest member
CALEB23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top