Mail Merge to Word -Problem with Access Form Code...

G

Guest

Could someone please look at this code and tell me what I am missing,
please? The problem that is occuring is I am given an error (5922)
that states "Word was unable to open the data source"

As an overview, I have a form where you can put the criteria to select
the data you want to print the forms by, the form has runreport button
witht he following code. When I click on the button, I get the above
mentioned error.

If I remove the long sql statement referring to the form, everything
works fine, but I am not able to 'filter' the data that I need to
print.

Any suggestions as to what I am doing wrong?

Thanks,

Ray.



Private Sub RunReport_Click()

Dim objWord As Word.Document
Set objWord = GetObject("e:\SUMMONSFORM.DOC", "Word.Document")

'Make Word Visible
objWord.Application.Visible = True

'Set Merge Data Source
objWord.MailMerge.OpenDataSource Name:="E:\CityTaxSaleV63.mdb", _
LinktoSource:=True, _
Connection:="QUERY qryOWNERCODEFENDANTsummonsmergedata", _
SQLStatement:="SELECT * FROM qryOWNERCODEFENDANTsummonsmergedata WHER
[taTAXSALESTATUS].[TaxSaleStatus]=forms!fmOWNERCODEFENDANTsummonsmergedata!TaxSaleStatus
AN
[taCOURTDATA].[TaxSaleNumber]=forms!fmOWNERCODEFENDANTsummonsmergedata!TaxSaleNumber"

'Execute the MailMerge
objWord.MailMerge.Execute

End Sub
 
G

Guest

Hi, does the file exist ? and at the path you specified ?
If yes, maybe try the following code to open the doc:

Dim strInputFile As String
strInputFile "file.doc" 'your file name
Set oApp = CreateObject("Word.Application")
oApp.Documents.Open strInputFile

and then your code....
good luck.
marc

"Ray Todd Jr" schreef:
 

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