I've scoured the various threads on the subject of mail merges from Access and it seems I am not alone in getting frustrated!
I have a mail merge document which extracts data directly from an Access 2007 query. This works fine from the Word menus,
however I want to run the merge from a command button within my Access application, which will select a subset of this query
data based on the record ID of the form I am in.
When I run the code, Word opens up but I get an error from Word saying the database has been placed in a state by user Admin
that prevents it from being opened or locked. Access VBA gives me a run-time error 5922.
Settings on Access are:
Default open mode : shared
Default record locking : no locks
Open databases by using record-level locking : no
Here's an extract of the code I have written.
Set objWord = GetObject(, "Word.Application")
If Err Then
Set objWord = New Word.Application
WordWasNotRunning = True
On Error GoTo err_handler
'Word Object is created - now let's fill it with data.
.Visible = True
Set myDoc = objWord.Documents.Add(strDocPath)
' allow time to open
.MainDocumentType = wdFormLetters
.OpenDataSource Name:="W:4. Databases and Documentsmydb.accdb", _
Connection:="QUERY myQuery", OpenExclusive:=False, _
LinkToSource:=False, ReadOnly:=True, _
SQLStatement:="SELECT * FROM myQuery where WFID = " & CStr(WorkflowID)
.Destination = wdSendToNewDocument
' do other stuff
Does anyone out there have any ideas?