Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access 2000: Passing from Form to Report - OnActivate/NoData Crash

Status
Not open for further replies.

marcus101

Programmer
Jan 21, 2003
64
CA
Hello:

I'm having some difficulties with handling a NoData event from a report, and I'm not entirely sure why I'm having them.

1. I have a form that grabs some info from a user, sets a query, and then opens my report.

2. I have some OnActivate code in the report which formats the report.

3. I'd like to ALSO have my NoData event handle situations where there are no records for the report.

I've set cancel = True for this step and have also added some error trapping code similar to RoyVidar's suggestions for bypassing error 2501 in the form VBA.

Here's the thing:

When I run the form/report, I get the message I included in the NoData event, so I know that is firing properly.

I also get a message I included in the ErrorTrap segment of my Form code, so I know that is firing.

However, once those items fire, Access just sits there and hangs, whereas I'd just like the user to be able to continue working with the form.

Obviously, I'm missing something, but I'm not quite sure what, maybe I need to handle the error differently, say using "On Error Resume Next" instead?

Right now I just have a statement like "On Error GoTo ErrorTrap:" that jumps to the error handling segment I've placed at the bottom of my form code.

Even more frustrating is that once I REMOVE the NoData event handling code the report opens up perfectly, no hangs or crashes, but has errors due to the lack of records (ie: none).

Obviously, I'd like to avoid opening up the report entirely in those cases where there are no records.

Maybe a DAO recordset example would do that better.

I can post more detailed code examples, but was wondering if there was any thoughts as to what might be the cause here - can I NOT use both the OnActivate AND NoData events at the same time?

Thanks.

marcus101

marcus101
Access/SQL/XML Developer
Ottawa, Canada
 
Well, it would probably help to have a little more info but I'm not sure what. I ran a report with the No Data event set to

Cancel = True
MsgBox "There is not data for this Report"

I get the message box and when I click OK, the whole thing just closes. The Activate event doesn't run as far as I can tell. What is the error trapping by RoyVidar that you refer to? It might help to know what you have for code throughout the whole process. This should work without this much trouble.

Paul
 
For what its worth, here's the code I put behind my reports to trap for no data:

Option Compare Database
Option Explicit
Dim varNoData As Integer

Private Sub Report_Activate()
If varNoData = 1 Then
Beep
Beep
MsgBox "yourmessagehere.", 64, "System message"
DoCmd.Close acReport, "yourreportname"
Else
End if
End Sub

Private Sub Report_NoData(Cancel As Integer)
varNoData = 1
End Sub

Good luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top