Mail Merge OpenDataSource Issue

S

Smythe32

The info below is from the Microsoft website. I am trying to do a mail
merge. The problem is the connection part of this code. This code
resides in the same db as query that will be providing the data for the
mail merge. When I run it, it says it can't access the data because
the db is locked. I presume because it is trying to open the same db
that I already have open.

How would I change the OpenDataSource portion to alleviate this?
Creating a new db for this process is not an option.

Thanks for any help,




1. Start Microsoft Access and open any database, or create a new one.
2. Create a module and type the following procedure: Function MergeIt()


Dim objWord As Word.Document
Set objWord = GetObject("C:\MyMerge.doc", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the Northwind database.
objWord.MailMerge.OpenDataSource _
Name:="C:\Program Files\Microsoft " & _
"Office\Office\Samples\Northwind.mdb", _
LinkToSource:=True, _
Connection:="TABLE Customers", _
SQLStatement:="SELECT * FROM [Customers]"
' 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