Manufacturing Information Solutions Forum Index Manufacturing Information Solutions
Your Place for Support and Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Close report automatically if no data found

 
Post new topic   Reply to topic    Manufacturing Information Solutions Forum Index -> Microsoft Access
View previous topic :: View next topic  
Author Message
mistux
Site Admin


Joined: 25 Jun 2004
Posts: 1042
Location: South Bend, Indiana USA

PostPosted: Wed Dec 03, 2008 5:51 pm    Post subject: Close report automatically if no data found Reply with quote

(Q) How can I close a report automatically if there's no data returned by the underlying query?

(A) You can use the Report's OnNoData event for this. For example, the following code

Code:
'************* Code Start *************
Private Sub Report_NoData(Cancel As Integer)
    MsgBox "No data found! Closing report."
    Cancel = True
End Sub
'************* Code End *************

will automatically close the report if there are no records in the underlying source.

However, if you're opening the report from code behind a form, you need to handle the error that's generated as a result.

Code:
'*********** Code Start ************
Private Sub TestNoData_Click()
    On Error Resume Next
    DoCmd.OpenReport "SomeReport", acViewPreview
    If Err = 2501 Then Err.Clear
End Sub
'*********** Code End   ************
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Manufacturing Information Solutions Forum Index -> Microsoft Access All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group