468,321 Members | 1,654 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,321 developers. It's quick & easy.

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

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
2 4506
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
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.

Similar topics

reply views Thread by webtrack+googlegroups | last post: by
reply views Thread by Gajendra | last post: by
2 posts views Thread by Steve M | last post: by
2 posts views Thread by Danny Ni | last post: by
2 posts views Thread by Mike Stephens | last post: by
4 posts views Thread by lesperancer | last post: by
4 posts views Thread by phil2phil | last post: by
2 posts views Thread by Alan T | last post: by
7 posts views Thread by =?Utf-8?B?QmFkaXM=?= | last post: by
1 post views Thread by =?Utf-8?B?QmFkaXM=?= | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by howard w | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.