By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,718 Members | 1,840 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,718 IT Pros & Developers. It's quick & easy.

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

P: n/a
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 WHERE
[taTAXSALESTATUS].[TaxSaleStatus]=forms!fmOWNERCODEFENDANTsummonsmergedata!TaxSaleS tatus
AND
[taCOURTDATA].[TaxSaleNumber]=forms!fmOWNERCODEFENDANTsummonsmergedata!TaxSaleN umber"

'Execute the MailMerge
objWord.MailMerge.Execute

End Sub

Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Ray,

The problems seems to be with the quotes in the query. You are passing Word
a reference to the Forms collecton in Access. In a mail merge, Word opens a
new instance of Access, and the Forms collection will have no open forms in
it. You should make all the values on your forms constants as far as your
query is concered. Your code should look something like this:

Connection:="QUERY qryOWNERCODEFENDANTsummonsmergedata", _
SQLStatement:="SELECT * FROM qryOWNERCODEFENDANTsummonsmergedata WHERE
[taTAXSALESTATUS].[TaxSaleStatus]= '" _
& forms!fmOWNERCODEFENDANTsummonsmergedata!TaxSaleSt atus _
& "AND [taCOURTDATA].[TaxSaleNumber]= "" _
& forms!fmOWNERCODEFENDANTsummonsmergedata!TaxSaleNu mber & "'"

Good luck,

Gary

"Ray Todd Jr" <sc*********@comcast.net> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
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 WHERE
[taTAXSALESTATUS].[TaxSaleStatus]=forms!fmOWNERCODEFENDANTsummonsmergedata!TaxSaleS tatus
AND
[taCOURTDATA].[TaxSaleNumber]=forms!fmOWNERCODEFENDANTsummonsmergedata!TaxSaleN umber"

'Execute the MailMerge
objWord.MailMerge.Execute

End Sub

Nov 13 '05 #2

P: n/a
Gary, thank you for your help!! That fixed my problem, everything
merges perfectly now.

Again, thanks...

Ray.

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.