Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 30th, 2006, 02:19 PM
Authorized User
 
Join Date: Sep 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to supress a report, If qry results = 0??

Hello to everyone out there on this rainy day in Detroit,

I need help in suppressing a report from printing or previewing in print preview mode if there are zero records in the query that the report is bound to. Right now, the report prints with #Error all over.

Does someone know how I can do that? What event should I act on or disable?

I was thinking on the report open event, check if the query's recordset is null then msgbox the user, then stop the report from going to print preview. But it's not working, well it's displaying the msgbox but I don't know how to disable the report from going to the report preview state.

Thanks for any help.

FJA


 
Old November 30th, 2006, 08:50 PM
Authorized User
 
Join Date: Nov 2006
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What is triggering the opening of the report? Could have a button or menu item that queries to see if there was a record returned then exectutes a the report if there is a record found


if rs.recordcount <> 0 then
  'DO COMMAND THAT EXECUTES THE REPORT
end if
 
Old November 30th, 2006, 11:19 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 217
Thanks: 0
Thanked 1 Time in 1 Post
Default

Try putting cancel = true to the ON_NoData Event of the report. You may want to give the user a message first.

ie:

msgbox "There was no information for the XXX report"
cancel = true




 
Old December 1st, 2006, 01:44 PM
Authorized User
 
Join Date: Sep 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you to both of your suggestions.

With regard to the second suggestion of setting cancel= true. I'm unsure as to where you're suggesting I do that.

When I go to the report event of "On No Data", I have the option of selecting one of the below:
1. event procedure
2. autoexec
3. mcrPageReset

The event procedure of On No Data displays the following:

Private Sub Report_NoData(Cancel As Integer)

End Sub

where Cancel is an integer parameter not a true/false data type. When I set cancel = -1, assuming -1 = true, it did not work to cancel the report from opening. It still opens w/ the #error.

FJA

 
Old December 1st, 2006, 02:41 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 217
Thanks: 0
Thanked 1 Time in 1 Post
Default

I have it in the NoData event of the report. Sorry for the mix up above- the instructor was just starting class when I scrawled that off..... You have a point about datatypes there- but with "cancel = true" it runs in my app. For grins I tried it with "cancel = vbtrue" and it ran also. The way I set it up is the report launches, and the Report OnOpen launches a dialog to populate the string for date parameter.
If you are using macros maybe someone can jump in and help you with that- I'm not that familiar with them.
HTH,
Loralee

See below:
============================================
Private Sub Report_NoData(Cancel As Integer)
On Error GoTo Error_Handler

    MsgBox "There are no patients who had an NPP sent on " & strDate
    Cancel = True

Exit Sub

Error_Handler:
   MsgBox "The CTU Database has encountered an error." & _
   vbCrLf & "Please contact your database support person and tell them this:" & _
   vbCrLf & "Error Number: " & Err.Number & " Description: " & Err.Description

Exit Sub

End Sub






Similar Threads
Thread Thread Starter Forum Replies Last Post
How to supress a report, If qry results = 0?? fazzou Crystal Reports 1 November 30th, 2006 02:21 PM
supress system (sqlserver) message starnet SQL Server 2000 1 July 28th, 2006 04:34 AM
supress pageheader of main report in subreport padma_eedara Crystal Reports 0 January 27th, 2006 09:07 AM
supress last value of a string kondapally Crystal Reports 0 December 16th, 2004 03:29 PM
Prb: COUNT qry result NOT SAME as SELECT qry savoym SQL Language 5 July 2nd, 2003 04:44 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.