Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mail Merge from Access to Word

Status
Not open for further replies.

primagic

IS-IT--Management
Jul 24, 2008
476
GB
Hi

I have the following code to merge a query into a word document. I can only merge all the records in the query. How would I amend the code to merge only the current record displayed on the form?

Also, when it merges into word, it brings up a confirm database box with various options like MS Access Databases via DDE, OLE DB Database Files and so on. Can I remove this?

Code:
Dim objWord As Word.Document
Set objWord = GetObject("E:\****\Clients\pwms\Master Due Diligence Template.doc", "Word.Document")

'Make Word Visible
objWord.Application.Visible = True

'Set Merge Data Source
objWord.MailMerge.OpenDataSource Name:="E:\***\Clients\pwms\dd.mdb", LinkToSource:=True, Connection:="QUERY qryDDDocumentMerge", SQLStatement:="SELECT*FROM qryDDDDocumentMerge"

'Execute the MailMerge
objWord.MailMerge.Destination = wdSendToNewDocument
objWord.MailMerge.Execute
 
Change SQLStatement:="SELECT*FROM qryDDDDocumentMerge"
to SQLStatement:="SELECT*FROM qryDDDDocumentMerge WHERE [Your Field] = YourCriteria"


Dunno about the warning. Have you tried docmd.setwarings = false ?

Tyrone Lumley
SoCalAccessPro
 
Can someone help me. I run the code below and it comes up with the message in word.

"Error has occured. The database has been placed in a state by user Admin on the machine....."

Any ideas how to overcome this?

Thanks

Code:
Dim objWord As Word.Document
Set objWord = GetObject("E:\****\Clients\pwms\Master Due Diligence Template.doc", "Word.Document")

'Make Word Visible
objWord.Application.Visible = True

'Set Merge Data Source
objWord.MailMerge.OpenDataSource Name:="E:\***\Clients\pwms\dd.mdb", LinkToSource:=True, Connection:="QUERY qryDDDocumentMerge", SQLStatement:="SELECT*FROM qryDDDDocumentMerge"

'Execute the MailMerge
objWord.MailMerge.Destination = wdSendToNewDocument
objWord.MailMerge.Execute
 
It is most likely the database is locked by a rouge user. Check if anyone is using the database and if not then delete the .ldb locking file (not the mdb).

Ian Mayor (UK)
Program Error
9 times out of 10 I know what I'm talking about. This must be my tenth reply.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top