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

On No Data Event run time error 2501 1

Status
Not open for further replies.

Brogrim

Technical User
Jul 28, 2000
184
0
0
IE
I am using a command button and and option box with values 1 – 5 to view reports in print preview

I added some error code to the “On No data” event to each of the reports.


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

This works, the message appears, I click OK but then I get a runtime error 2501 the open report action was cancelled. When I click on the debug button it brings me to this line of code

Else: DoCmd.OpenReport "rptMemberASLHB", acViewPreview

in this block of code

Case Is = 1

If IsNull([cboHSEID]) Then
MsgBox "Please Select a Health Board Area"
DoCmd.GoToControl "cboHSEID"
cboHSEID.Dropdown
Else: DoCmd.OpenReport "rptMemberASLHB", acViewPreview
End If

Any idea's how to handle no data when the reports are pulled from select statements
 
You need an error handler in the block of code/function/subroutine that has the DoCmd.OpenReport command in it.

THen, in that error handler you need to ignore 2501 errors, e.g.

If Err.Number <> 2501 Then MsgBox Err.Number & ": " & Err.Description
Resume ..... wherever you want to resume

[pc2]
 
Thank you, I am very new to this

Where does the

If Err.Number <> 2501 Then MsgBox Err.Number & ": " & Err.Description

go in the code

Private Sub cmdMemASL_Click()

Case Is = 1

If IsNull([cboHSEID]) Then
MsgBox "Please Select a Health Board Area"
DoCmd.GoToControl "cboHSEID"
cboHSEID.Dropdown

Else: DoCmd.OpenReport "rptMemberASLHB", acViewPreview

End If

Case Is = 2

If IsNull([cboHSERegionID]) Then
MsgBox "Please Select a HSE Region"
DoCmd.GoToControl "cboHSERegionID"
cboHSERegionID.Dropdown

Else: DoCmd.OpenReport "rptMemberASLHSERegion", acViewPreview

End If

End Select

End Sub

Thanks
 
Something like this (although you missed the first line of your SELECT statement, so I had to make that up (the bit in red)):
Code:
Private Sub cmdMemASL_Click()
On Error GoTo Err_cmdMemASL_Click
[red]Select Case WhateverYouAreSelectingHere[/red]
Case Is = 1
    
    If IsNull([cboHSEID]) Then
        MsgBox "Please Select a Health Board Area"
        DoCmd.GoToControl "cboHSEID"
        cboHSEID.Dropdown
    Else
        DoCmd.OpenReport "rptMemberASLHB", acViewPreview
    End If

Case Is = 2
       
    If IsNull([cboHSERegionID]) Then
        MsgBox "Please Select a HSE Region"
        DoCmd.GoToControl "cboHSERegionID"
        cboHSERegionID.Dropdown
    Else
        DoCmd.OpenReport "rptMemberASLHSERegion", acViewPreview
    End If
                
End Select

Exit_cmdMemASL_Click:
Exit Sub

Err_cmdMemASL_Click:
If Err.Number <> 2501 Then MsgBox Err.Number & ": " & Err.Description
Resume Exit_cmdMemASL_Click
End Sub

[pc2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top