sashapixie
Board Regular
- Joined
- Aug 29, 2013
- Messages
- 71
- Office Version
- 365
- Platform
- 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
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