Crash

Lord Justin

Registered User.
Local time
Tomorrow, 01:09
Joined
Oct 15, 2007
Messages
15
Hi,
I have a problem with reports again. :p I want to close my report in the opening, if there is no record. For this thing, I can use "On No Data" event. But if I use this event for closing the report, Access crashes. Because pop up property of report is on. If the property is off, Access doesn't crash. Any idea? :rolleyes:

Note:
I'm using Access 2007.
 
Last edited:
When you say it crashes, what does it do? I usually use the On No Data event to cancel the opening and trap for error 2501 the "You canceled this event."
 
Okay, so why are you closing the form in the On No Data event?
 
Ah, that's your problem. In the On No Data event use this:
Code:
Msgbox "No data is currently available at this time for this report", vbInformation, "No Data"
Cancel = True

That will close the report automatically but also give the user an informative message that tells them why it is closing.

Also, you will need to trap for error 2501 ("you canceled this event" error) in the code for the item that actually opened the report to begin with. So, if a button click event opened the report then put this at the top of your click event:
Code:
On Error GoTo err_handler

And at the bottom of the event put:
Code:
Exit Sub
err_handler:
   If err.Number = 2501 Then
      Exit Sub
   Else
      MsgBox err.Description, vbExclamation, "Error #: " & err.Number
   End If
End Sub
 
Ah, that's your problem. In the On No Data event use this:
Code:
Msgbox "No data is currently available at this time for this report", vbInformation, "No Data"
Cancel = True

That will close the report automatically but also give the user an informative message that tells them why it is closing.

Code works well. But it didn't give any error message.:D Is this normal? Maybe this is only for previous versions of Access? I'm using Access 2007:rolleyes:
 
Code works well. But it didn't give any error message.:D Is this normal? Maybe this is only for previous versions of Access? I'm using Access 2007:rolleyes:

That could be. I don't think I've tried it yet in 2007. Glad we got it sorted for you.
 

Users who are viewing this thread

Back
Top Bottom