Log in

View Full Version : Opening a word document with VBA ignores mail merge?



Nomad
06-23-2015, 06:57 AM
Hi

Basically at the moment I am working on a database. In the database it has a form which allows you to input a comment for a specific user by selecting their ID from a box. What I want to do, is have users be able to select the ID (which then brings through all the information) and then press a button and have a mail merged document open, completed with the information. I have googled the problem and come up with a few work arounds, as it does not appear possible to create a mail merge direct from a report with varying criteria.

I have done this by creating the mail merge document, then linking it to a "temporary table" which is created by a "make table" query, that takes the information from the selected user and puts it into the table when a button is pressed. If I then open the word document from Windows Explorer it all works fine. However, if I use VBA to open the document it skips the window that asks if you'd like to connect to the data source and does not update the information, all the "links" to the database are ignored, it opens up as a static document.

I am very new to VBA (although I do know some C# and SQL), having only started about two weeks ago. The VBA I am using is:


Private Sub

bttnTemp_Click()DoCmd.OpenQuery "qryMailMerge"


'Runs the mailmerge query


Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim filepath As String


'Open Word
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True


filepath = "C:\Users\PRIVATE\Documents\......."


'Open the file
Set wrdDoc = wrdApp.Documents.Open(filepath)


End Sub

Does anybody have any suggestions?

Nomad
06-23-2015, 10:48 AM
Application.FollowHyperlink is a godsend.