Ignore Error Not Working???

S

saraqpost

This is driving me crazy! I have looked a posts and MS web and tried
to fix, but I keep getting the 2501 error after I show my No Data
message to the user.

Can someone help? I know I'm new, but this looked easy!

thanks
Sara

Print Preview Button Code:

Private Sub cmdPreview_Click()
On Error GoTo Err_cmdPreview_Click

' Figure out which report the user is requesting and run it

Dim strReportName As String

Select Case Me.fraReports

Case Is = 1
' By First name
strReportName = "rptByFirstName"

Case Is = 2
' By Last name
strReportName = "rptByLastName"


Case Is = 3
' By Location
strReportName = "rptByLocation"


Case Is = 4
' By Date - or range
strReportName = "rptByDate"


Case Is = 5
' By Department
strReportName = "rptByDepartment"


End Select

' Debug goes to this line after No data event - with 2501 error
DoCmd.OpenReport strReportName, acViewPreview


Exit_cmdPreview_Click:
Exit Sub

Err_cmdPreview_Click:
If Err.Number = 2501 Then
Err.Clear
Else
MsgBox Err.Number & " " & Err.Description
End If

Resume Exit_cmdPreview_Click



No Data Event Report Code:

Private Sub Report_NoData(Cancel As Integer)

Dim strDepartment As String

strDepartment =
[Forms]![frmEmployeeSurveyed]![cboDepartment].Column(1)

'Tell the user there is no data

MsgBox "There are no shopping reports for the Department chosen: "
& _
strDepartment

Cancel = True

End Sub
 
A

Allen Browne

Set up the error handler to just ignore the error, like this:

Err_cmdPreview_Click:
If Err.Number <> 2501 Then
MsgBox Err.Number & " " & Err.Description
End If
Resume Exit_cmdPreview_Click
 
S

saraqpost

Though I think I had tried this before, I copied and pasted your code
to replace my error handler, and I'm still getting the 2501 on the
DoCmd.OpenReport line in the code from the PrintPreview button.

"Run-Time Error '2501'. The OpenReport action was canceled"

Any ideas?

Thanks
Sara




Allen said:
Set up the error handler to just ignore the error, like this:

Err_cmdPreview_Click:
If Err.Number <> 2501 Then
MsgBox Err.Number & " " & Err.Description
End If
Resume Exit_cmdPreview_Click

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

This is driving me crazy! I have looked a posts and MS web and tried
to fix, but I keep getting the 2501 error after I show my No Data
message to the user.

Can someone help? I know I'm new, but this looked easy!

thanks
Sara

Print Preview Button Code:

Private Sub cmdPreview_Click()
On Error GoTo Err_cmdPreview_Click

' Figure out which report the user is requesting and run it

Dim strReportName As String

Select Case Me.fraReports

Case Is = 1
' By First name
strReportName = "rptByFirstName"

Case Is = 2
' By Last name
strReportName = "rptByLastName"


Case Is = 3
' By Location
strReportName = "rptByLocation"


Case Is = 4
' By Date - or range
strReportName = "rptByDate"


Case Is = 5
' By Department
strReportName = "rptByDepartment"


End Select

' Debug goes to this line after No data event - with 2501 error
DoCmd.OpenReport strReportName, acViewPreview


Exit_cmdPreview_Click:
Exit Sub

Err_cmdPreview_Click:
If Err.Number = 2501 Then
Err.Clear
Else
MsgBox Err.Number & " " & Err.Description
End If

Resume Exit_cmdPreview_Click



No Data Event Report Code:

Private Sub Report_NoData(Cancel As Integer)

Dim strDepartment As String

strDepartment =
[Forms]![frmEmployeeSurveyed]![cboDepartment].Column(1)

'Tell the user there is no data

MsgBox "There are no shopping reports for the Department chosen: "
& _
strDepartment

Cancel = True

End Sub
 
S

saraqpost

Though I think I had tried this before, I copied and pasted your code
to replace my error handler, and I'm still getting the 2501 on the
DoCmd.OpenReport line in the code from the PrintPreview button.

"Run-Time Error '2501'. The OpenReport action was canceled"

Any ideas?

Thanks
Sara




Allen said:
Set up the error handler to just ignore the error, like this:

Err_cmdPreview_Click:
If Err.Number <> 2501 Then
MsgBox Err.Number & " " & Err.Description
End If
Resume Exit_cmdPreview_Click

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

This is driving me crazy! I have looked a posts and MS web and tried
to fix, but I keep getting the 2501 error after I show my No Data
message to the user.

Can someone help? I know I'm new, but this looked easy!

thanks
Sara

Print Preview Button Code:

Private Sub cmdPreview_Click()
On Error GoTo Err_cmdPreview_Click

' Figure out which report the user is requesting and run it

Dim strReportName As String

Select Case Me.fraReports

Case Is = 1
' By First name
strReportName = "rptByFirstName"

Case Is = 2
' By Last name
strReportName = "rptByLastName"


Case Is = 3
' By Location
strReportName = "rptByLocation"


Case Is = 4
' By Date - or range
strReportName = "rptByDate"


Case Is = 5
' By Department
strReportName = "rptByDepartment"


End Select

' Debug goes to this line after No data event - with 2501 error
DoCmd.OpenReport strReportName, acViewPreview


Exit_cmdPreview_Click:
Exit Sub

Err_cmdPreview_Click:
If Err.Number = 2501 Then
Err.Clear
Else
MsgBox Err.Number & " " & Err.Description
End If

Resume Exit_cmdPreview_Click



No Data Event Report Code:

Private Sub Report_NoData(Cancel As Integer)

Dim strDepartment As String

strDepartment =
[Forms]![frmEmployeeSurveyed]![cboDepartment].Column(1)

'Tell the user there is no data

MsgBox "There are no shopping reports for the Department chosen: "
& _
strDepartment

Cancel = True

End Sub
 
A

Allen Browne

If the DoCmd.OpenReport line still gives error 2051, then your error handler
is not being invoked.

1. Place the cursor in the Select Case ... line.
2. Press F9 to insert a break point.
3. Click the button. It will stop at the line with the break point.
4. Press F8 repeatedly to step through the code, and see what is executing.
Take notice of what it is doing.

When it reaches the End Select line, pause the mouse over strReportName to
see how it is set. When it reaches the OpenReport line, does it actually go
to the error handler?

The construct:
Case Is = 1
is unusual. You can just use:
Case 1

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Though I think I had tried this before, I copied and pasted your code
to replace my error handler, and I'm still getting the 2501 on the
DoCmd.OpenReport line in the code from the PrintPreview button.

"Run-Time Error '2501'. The OpenReport action was canceled"

Any ideas?

Thanks
Sara




Allen said:
Set up the error handler to just ignore the error, like this:

Err_cmdPreview_Click:
If Err.Number <> 2501 Then
MsgBox Err.Number & " " & Err.Description
End If
Resume Exit_cmdPreview_Click

This is driving me crazy! I have looked a posts and MS web and tried
to fix, but I keep getting the 2501 error after I show my No Data
message to the user.

Can someone help? I know I'm new, but this looked easy!

thanks
Sara

Print Preview Button Code:

Private Sub cmdPreview_Click()
On Error GoTo Err_cmdPreview_Click

' Figure out which report the user is requesting and run it

Dim strReportName As String

Select Case Me.fraReports

Case Is = 1
' By First name
strReportName = "rptByFirstName"

Case Is = 2
' By Last name
strReportName = "rptByLastName"


Case Is = 3
' By Location
strReportName = "rptByLocation"


Case Is = 4
' By Date - or range
strReportName = "rptByDate"


Case Is = 5
' By Department
strReportName = "rptByDepartment"


End Select

' Debug goes to this line after No data event - with 2501 error
DoCmd.OpenReport strReportName, acViewPreview


Exit_cmdPreview_Click:
Exit Sub

Err_cmdPreview_Click:
If Err.Number = 2501 Then
Err.Clear
Else
MsgBox Err.Number & " " & Err.Description
End If

Resume Exit_cmdPreview_Click



No Data Event Report Code:

Private Sub Report_NoData(Cancel As Integer)

Dim strDepartment As String

strDepartment =
[Forms]![frmEmployeeSurveyed]![cboDepartment].Column(1)

'Tell the user there is no data

MsgBox "There are no shopping reports for the Department chosen: "
& _
strDepartment

Cancel = True

End Sub
 
S

saraqpost

I tried as you suggested. I even changed my syntax to Case 1 (much
simpler to read, thanks!)

NO, when the code reaches DoCme.OpenReport, it does NOT go to the error
handler. I actually had set the breakpoint in the past and tried it,
and never got to my own error handling code.

How do I make the error handling code execute? I thought the On Error
would do it; does it have something to do with my NoData event or
something?

thanks (again!)
Sara
 
A

Allen Browne

The code should read go to the error handler as you expect.

Does the code give you errors if you choose Compile on the Debug menu?
 
S

saraqpost

Well, I just released the breath I've been holding all this time! I
feel better that it's not so obvious even to you.

There are no errors - clean compile. That's a lesson I've learned
well. Any change - I compile.

I can zip it up and send it to you somewhere - nothing confidential,
and it's small. (If that helps)

sara
 
A

Allen Browne

Sara, go to the code window, and choose Options from the Tools menu.
On the General tab of the dialog, what setting do you have for:
Error Trapping
 
S

saraqpost

That was it!!!! I had Break on All Errors, left over, I'm sure, from my
trying to figure something out a while ago. I can't seem to remember
to change that back after I set it - works great now! (Break on
unhandled errors is what I chose).

I can't thank you enough for sticking with this for the past few days.
Now, maybe next time I'll remember to check my error trapping whenever
I have a problem.

Sara
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top