PDA

View Full Version : Access VBA - Opening a mailmerge word document



jeskit
12-03-2013, 04:25 AM
Hi,

In my access database I have a module which when a button is pressed it opens a mail merge word document which is linked to the a table in the database. However before word opens it comes up with a message saying "Data from your database will be paced in the document. Do you want to continue?" which you need to select yes or no to before word opens.

The problem is this message constantly appears behind access so for me to see the message I have to minimise access.

Dose anyone know why it does this or how I can get it to stop? The code for the mail merge document is below?



Private Sub mailmerge_Click()
Dim strFilePath As String
Dim objWord As Word.Document
DoCmd.RunMacro "ref2"
strFilePath = "c:\Further Requirements.docx"

Set objWord = GetObject(strFilePath, "Word.Document")

objWord.Application.Visible = True

objWord.MailMerge.OpenDataSource _
Name:="C:\jeskitdatabase.mdb", _
LinkToSource:=True, _
Connection:="TABLE members", _
SQLStatement:="SELECT * FROM [members] WHERE [ID]=[Ref2]"


Set objWord = Nothing
End Sub

Thank you
Kind regards
Jeskit