Access Mail Merge in Word Data Link Error

O

omsoft

I am doing a mail merge to a Word template from an Access query. It is a
onClick event on a button. The code is as below.
It opens the Word template and then comes up with Data Link Properties
dialog. When I click OK, I get a message as below.
"The database has been placed in a state by user 'Admin' on machine 'MY'
that prevents it from being opened or locked."
When I click OK, it comes up with a Login dialog for MS Access database. If
I click OK, it will post the above message again. If I click Cancel, it goes
ahead with the merge.

Does anyone know how can I get rid of these messages? Thanks a million.

Dim strDir As String
Dim objWord As New Word.Application
Dim objDoc As Word.Document
strDir = getMDBPath
objWord.Application.Visible = True
Set objDoc = objWord.Documents.Open(strDocName)
objWord.Application.Visible = True

objDoc.MailMerge.OpenDataSource _
Name:=getThisDBPath(), _
LinkToSource:=True, AddToRecentFiles:=False, _
Connection:="QUERY qry_MailMerge_1", _
SQLStatement:="SELECT * FROM [qry_MailMerge_1]"
objDoc.MailMerge.Destination = wdSendToNewDocument
objDoc.MailMerge.Execute

objWord.Application.Documents(1).SaveAs (strMergedDocName & ".doc")
objWord.Application.Documents(2).Close wdDoNotSaveChanges
objWord.Application.Documents(1).Close wdSaveChanges
objWord.Quit
Set objWord = Nothing
Set objDoc = Nothing
 

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