run a mail merge from an access query

M

Mike

I have set up a word merge document and can run it from word and access the
data in the access query but whenever i try to run the following code from an
on click event in the database I get a message stating that " user admin has
placed the database in a state that cannot be opened or locked" I have no
passwords set on the database. and the database is a front end back end type.
I would like the code to run the merge and open the merged document only

Thanks in advance for any help


Function MergeIt()
Dim objWord As Word.Document
Set objWord = GetObject("D:\Documents and Settings\Mike\My
Documents\letsurgery.doc", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the newtheatreforms database.
objWord.MailMerge.OpenDataSource _
Name:="D:\Documents and Settings\Mike\My
Documents\newtheatreforms.mdb", _
ConfirmConversions:=False, _
ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="",
WritePasswordDocument:="", _
WritePasswordTemplate:="", Revert:=False, Format:=0, _
Connection:="TABLE query1", _
SQLStatement:="SELECT * FROM [query1]"
' Execute the mail merge.
objWord.MailMerge.Execute
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top