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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using NoData & Error Handler - still coming up with 2501 runtime error 2

Status
Not open for further replies.

r0nniem

Technical User
Dec 22, 2005
28
AU
Can you please help? This form opens several reports based on the criteria entered - select the report name, and select/enter data to view report.

In each report I have:

Private Sub Report_NoData(Cancel As Integer)
MsgBox "There is no data for this report. Canceling report."
Cancel = True
End Sub

In the form I have:

Private Sub Preview_Click()
On Error GoTo Preview_Click_Err

If IsNull(Me![cmbReport]) Then
MsgBox "You must select a report to run.", vbInformation, "Status"
DoCmd.GoToControl "cmbreport"
Exit Sub
End If

If IsNull(Me![cmbCust]) And Me![cmbCust].Enabled = True Then
MsgBox "You must select a Customer.", vbInformation, "Status"
DoCmd.GoToControl "cmbCust"
Exit Sub
End If

If IsNull([cmbJobType]) And Me![cmbJobType].Enabled = True Then
MsgBox "You must select a Job Type.", vbInformation, "Status"
DoCmd.GoToControl "cmbjobtype"
Exit Sub
End If

If IsNull(Me![BegTransDate1]) And Me![cmbMonth].Enabled = True Then
MsgBox "You must select a Month.", vbInformation, "Status"
DoCmd.GoToControl "cmbMonth"
Exit Sub
End If

If IsNull(Me![cmbYear]) And Me![cmbYear].Enabled = True Then
MsgBox "You must select a Year.", vbInformation, "Status"
DoCmd.GoToControl "cmbYear"
Exit Sub
End If

If Me![cmbYear].Visible = False Then
If IsNull([BegTransDate]) Or IsNull([EndTransDate]) Then
MsgBox "You must enter both beginning and ending date", vbInformation, "Status"
DoCmd.GoToControl "BegTransDate"
Else
If [BegTransDate] > [EndTransDate] Then
MsgBox "Ending date must be greater that Beginning date.", vbInformation, "Status"
DoCmd.GoToControl "BegTransDate"
Else
DoCmd.OpenReport [cmbReport], acViewPreview
End If
End If
Else
DoCmd.OpenReport [cmbReport], acViewPreview
End If

Preview_Click_Exit:
Exit Sub

Preview_Click_Err:
If Err <> 2501 Then MsgBox Err.Description

End Sub

I'm not sure what I'm doing wrong ... can you please help me out?
 
Ji JoeAtWork,

Sorry ... it's in the title. At the first DoCmd.OpenReport [cmbReport], acViewPreview, it comes up with the message from the report "There is no data for this report. Canceling report." then steps back to the same line (DoCmd.OpenReport [cmbReport]) and comes up with the Runtime 2501 error.

Thanks

 
On the no data you are canceling the report but your code to run the report is calling a msgbox to handle the 2501 error. the error is displayed not by your Onnodata code but by your print preview code. Err Handle code below will allow you to ignore the err from your print preview code and allow the on no data code to handle the 2501. It also gives you the option to handle any other specific err codes with the Case else statement

Preview_Click_Err:
Select Case Err
Case 2501
'ignore
Case Else
'other err code here
End Select

HTH << MaZeWorX >> Remember amateurs built the ark - professionals built the Titanic [flush]
 
Or, IF err.number = 2501 THEN err.clear.

Cogito eggo sum – I think, therefore I am a waffle.
 
Thank you genomon and MaZeWorX,

I tried both your suggestions and still no luck. When I stepped through the code just as you said MaZeWorX, the report it doing the right thing, it's the form's code at the doCmd to open the report. It's like the error handler isn't working.

Here's updated code:

Private Sub Preview_Click()
On Error GoTo Preview_Click_Err

If IsNull(Me![cmbReport]) Then
MsgBox "You must select a report to run.", vbInformation, "Status"
DoCmd.GoToControl "cmbreport"
Exit Sub
End If

If IsNull(Me![cmbCust]) And Me![cmbCust].Enabled = True Then
MsgBox "You must select a Customer.", vbInformation, "Status"
DoCmd.GoToControl "cmbCust"
Exit Sub
End If

If IsNull([cmbJobType]) And Me![cmbJobType].Enabled = True Then
MsgBox "You must select a Job Type.", vbInformation, "Status"
DoCmd.GoToControl "cmbjobtype"
Exit Sub
End If

If IsNull(Me![BegTransDate1]) And Me![cmbMonth].Enabled = True Then
MsgBox "You must select a Month.", vbInformation, "Status"
DoCmd.GoToControl "cmbMonth"
Exit Sub
End If

If IsNull(Me![cmbYear]) And Me![cmbYear].Enabled = True Then
MsgBox "You must select a Year.", vbInformation, "Status"
DoCmd.GoToControl "cmbYear"
Exit Sub
End If

If Me![cmbYear].Visible = False Then
If IsNull([BegTransDate]) Or IsNull([EndTransDate]) Then
MsgBox "You must enter both beginning and ending date", vbInformation, "Status"
DoCmd.GoToControl "BegTransDate"
Else
If [BegTransDate] > [EndTransDate] Then
MsgBox "Ending date must be greater that Beginning date.", vbInformation, "Status"
DoCmd.GoToControl "BegTransDate"
Else
DoCmd.OpenReport [cmbReport], acViewPreview
End If
DoCmd.OpenReport [cmbReport], acViewPreview
End If
End If

Preview_Click_Exit:
Exit Sub

Preview_Click_Err:
Select Case Err.Number
Case 2501
Resume Preview_Click_Exit
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description
Resume Preview_Click_Exit
End Select

End Sub

 
Select Case Err ... remove number

HTH << MaZeWorX >> Remember amateurs built the ark - professionals built the Titanic [flush]
 
I tried it out on another PC and it all works fine ... both are Access 2003 SP3 ... so the code is fine ... have to investigate further. Thank you for your assistance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top