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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mailmerge using a query with a prompt

Status
Not open for further replies.

MarkusArchus

Programmer
Jun 12, 2000
6
US
I am using the following code to open a Word document and use an Access query as the data source. (For test purposes I've hard coded the file and query names but eventually they will be variables.)

Function testmerge()
Dim db As Database, wrd As Object
Set db = CurrentDb
Set wrd = GetObject("d:\apprentice\dc35\merge test.doc", _
"Word.Document")
wrd.Application.Visible = True
wrd.mailmerge.OpenDataSource _
Name:=db.Name, _
LinkToSource:=True, _
Connection:="QUERY Apprentice Merge", _
SQLStatement:="select * from [Apprentice Merge]"
wrd.mailmerge.viewmailmergefieldcodes = False
Set wrd = Nothing
End Function

This works fine with a plain vanilla query. But if I add a prompt to the query and run this code, I get prompted as I normally would when running the query, but then after I enter data at the prompt, I get an error message: "Word was unable to open the data source."

I use prompt queries all the time in mail merges that I set up manually, whether I use the mail merge wizard in Word, or the Office Links in Access. Is there something special I need to do to make it work when I use VBA code to run the merge?

TIA.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top