dbTalk Databases Forums  

macro won't close report with no recoreds

comp.databases.ms-access comp.databases.ms-access


Discuss macro won't close report with no recoreds in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Tony_E
 
Posts: n/a

Default macro won't close report with no recoreds - 01-21-2011 , 09:18 AM






Hello
Access 2003. I am trying to program a macro to close a report
automatically. When the report has records this is not a problem.
When the report does not have records a MS Office Access message comes
up reading "The report named 'sales' you entered is misspelled or
refers to a report that is not open or doesn't exist." Does anybody
have any recommendations?

Thanks
Tony

Reply With Quote
  #2  
Old   
Access Developer
 
Posts: n/a

Default Re: macro won't close report with no recoreds - 01-21-2011 , 02:07 PM






The simplest approach is not to Open the Report unless its Record Source
Query produces Records. Use the Report's Query in a DCOUNT domain aggregate
statement, something like the following where the Report is called "Arep",
its RecordSource is "AQry", and "AFld" is any field that will have a value
for each record (like, say, the key field for the records):

If DCOUNT("AFld","AQry") > 0 Then
DoCmd.OpenReport ("Arep")
End If

Larry Linson
Microsoft Office Access MVP

Tony_E" <bluestealth94 (AT) hotmail (DOT) com> wrote

Quote:
Hello
Access 2003. I am trying to program a macro to close a report
automatically. When the report has records this is not a problem.
When the report does not have records a MS Office Access message comes
up reading "The report named 'sales' you entered is misspelled or
refers to a report that is not open or doesn't exist." Does anybody
have any recommendations?

Thanks
Tony

Reply With Quote
  #3  
Old   
James A. Fortune
 
Posts: n/a

Default Re: macro won't close report with no recoreds - 01-31-2011 , 09:50 AM



On Jan 21, 3:07*pm, "Access Developer" <accde... (AT) gmail (DOT) com> wrote:
Quote:
The simplest approach is not to Open the Report unless its Record Source
Query produces Records. *Use the Report's Query in a DCOUNT domain aggregate
statement, something like the following where the Report is called "Arep",
its RecordSource is "AQry", and "AFld" is any field that will have a value
for each record (like, say, the key field for the records):

* * If DCOUNT("AFld","AQry") > 0 Then
* * * * DoCmd.OpenReport ("Arep")
* * End If

*Larry Linson
* Microsoft Office Access MVP

Tony_E" <bluestealt... (AT) hotmail (DOT) com> wrote in message

news:67b01c5b-f705-44ae-8aa8-e1969cccadec (AT) m7g2000vbn (DOT) googlegroups.com...

Hello
Access 2003. I am trying to program a macro to close a report
automatically. *When the report has records this is not a problem.
When the report does not have records a MS Office Access message comes
up reading "The report named 'sales' you entered is misspelled or
refers to a report that is not open or doesn't exist." *Does anybody
have any recommendations?

Thanks
Tony
I like how Larry's technique also excludes cases where the query
returns records, but all the values of AFld are all Null.

James A. Fortune
CDMAPoster (AT) FortuneJames (DOT) com

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.