Launching word mail merge from form

skiefer

Registered User.
Local time
Today, 04:07
Joined
Aug 1, 2004
Messages
21
Hi again - With the help of a post in the VB forum, I have created the following code to automatically launch word and run a mail merge. The problem is that I get an error message opening up the mdb database, stating that it's locked by another user.

How do I force the mail merge to open in read-only? Alternatively, I got the mail merge to work using a query against the table instead of opening the table itself, but I can'f figure out how to update this code to call a query. I thought I could just change to table name to a query name, but that gives me an 'application defined error'

Can anyone help??? Please?

Private Sub Preview_Report_Click()

On Error GoTo Err_merge_Click
'Developed by Robert Sang for Connect Learning Centres 2003

'Load the mail merge document as an object
Dim objWord As Object
Set objWord = GetObject("C:\ABC\Labels_Blank.doc", "Word.Document")
'Make Word visible
objWord.Application.Visible = True

'Open the mail merge data source (this database and record)
objWord.MailMerge.OpenDataSource _
Name:="C:\Personal_Chef\Label.mdb", _
LinkToSource:=True, _
Connection:="TBLabels", _
SQLStatement:="SELECT * FROM [TBLabels] "
'Execute the mail merge
objWord.MailMerge.Execute

Exit_merge_Click:
Exit Sub

Err_merge_Click:
MsgBox Err.Description
Resume Exit_merge_Click

End Sub
 
Have a look at the attached sample, it is not mine. I found it on the web and it works fine.

One of its many features is that you can have multiple templates linked to the database.
Open and read the modules especially "Word Code".

Hope this helps,
 
Missed the attachment

I don't seem to be able to attach the file it is a zip file size 72 kb.

Any suggestions??
 

Users who are viewing this thread

Back
Top Bottom