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

Mail Merge using Query not Working?

Status
Not open for further replies.

bluedollar

Programmer
Jul 24, 2003
174
GB
I have a mail merge that is not working, the code I am using is shown below ([sf18_data] is a query):

DoCmd.RunCommand acCmdSaveRecord
Dim oDoc As Word.Document
Set oDoc = GetObject("C:\sf18.doc", "Word.Document")
oDoc.Application.Visible = True
oDoc.MailMerge.OpenDataSource _
Name:="c:\windows\desktop\select.mdb", _
linktosource:=True, _
Connection:="QUERY sf18_data", _
SQLStatement:="Select * From [sf18_data] where [sf18_data].ID = " & Me.Text95
oDoc.MailMerge.Execute
DoCmd.Close acForm, "sf18", acSaveNo

At the moment I get the following error message:

error: 5922 Word was unable to open the datasource

If I change the SQlstatement to:

SQLStatement:="Select * From [sf18_data]"

Then the merge works fine, however all the records in the recordset are merged.

Also a new copy of the select.mdb is opened, is there any way to prevent this.

Any help would be greatly appreciated.

Thanks

Dan


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top