473,507 Members | 2,476 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trapping Error 2501

I have the following code in the On No Data event of a report:

****
On Error GoTo err_trap

MsgBox "No items matching criteria.", vbInformation, gcApplication
Cancel = True

err_trap:
If Err.Number = 2501 Then Exit Sub
****

When the code pointer returns to the calling line:

****
DoCmd.OpenReport Forms(gcFrmPrint).lstReport.Column(1), acViewPreview, ,
strCriteria
****

error 2501 is raised, even though I'm trapping for it both in the calling
procedure and the report code.

Am I missing something obvious? I'm guessing I am :o0

Regards,
Keith.
Nov 13 '05 #1
4 9426
"Keith" <ke*********@baeAWAYWITHITsystems.com> wrote in message
news:42**********@glkas0286.greenlnk.net...
I have the following code in the On No Data event of a report:

****
On Error GoTo err_trap

MsgBox "No items matching criteria.", vbInformation, gcApplication
Cancel = True

err_trap:
If Err.Number = 2501 Then Exit Sub
****

When the code pointer returns to the calling line:

****
DoCmd.OpenReport Forms(gcFrmPrint).lstReport.Column(1), acViewPreview, ,
strCriteria
****

error 2501 is raised, even though I'm trapping for it both in the calling
procedure and the report code.

Am I missing something obvious? I'm guessing I am :o0

Regards,
Keith.


Hi Keith
I can't see the error handling in the other procedure - but there is no
point looking for 2501 in two places. Here is a typical example where a
command button opens a report. There is no error handling in the NoData
event - you could put some in - but the place to catch 2501 is in the
preview button's OnClick event.
Private Sub Report_NoData(Cancel As Integer)
MsgBox "No matching records"
Cancel = True
End Sub
Private Sub cmdReport_Click()

On Error GoTo Err_Handler

DoCmd.OpenReport "MyReport", acViewPreview

Exit_Handler:
Exit Sub

Err_Handler:

Select Case Err.Number

Case 2501
' The report has been cancelled due to no data
' The report's coding shows the message,
' so no need for another one here.

Case Else
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number

End Select

Resume Exit_Handler

End Sub
Nov 13 '05 #2
"Justin Hoffman" <j@b.com> wrote in message
news:db**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...

Hi Keith
I can't see the error handling in the other procedure - but there is no
point looking for 2501 in two places. Here is a typical example where a
command button opens a report. There is no error handling in the NoData
event - you could put some in - but the place to catch 2501 is in the
preview button's OnClick event.

Thanks Justin. Trapping in more that one place was an act of desperation
;-p

This is what I have in the command button Click event:

****
Private Sub cmdPreview_Click()

On Error GoTo err_trap

Dim strCriteria As String
strCriteria = Me.OpenArgs & " = '" & Me.cboActionee & "'"
If Me.ogrClosed <> 3 Then strCriteria = strCriteria & " And [Closed] = " &
Me.ogrClosed
Me.Visible = False
DoCmd.OpenReport Forms(gcFrmPrint).lstReport.Column(1), acViewPreview, ,
strCriteria
DoCmd.Maximize

err_trap:
If Err.Number = 2501 Then Exit Sub

End Sub
****

I'll try your version in the meantime, but I'm wondering if some of the
other stuff I'm doing is upsetting Access. I'm basically using the same
filter form for two different reports. I'm using OpenArgs to pass the name
of the field to filter on.

Regards,
Keith.
Nov 13 '05 #3
"Keith" <ke*********@baeAWAYWITHITsystems.com> wrote in message
news:42**********@glkas0286.greenlnk.net...
"Justin Hoffman" <j@b.com> wrote in message
news:db**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...

Hi Keith
I can't see the error handling in the other procedure - but there is no
point looking for 2501 in two places. Here is a typical example where a
command button opens a report. There is no error handling in the NoData
event - you could put some in - but the place to catch 2501 is in the
preview button's OnClick event.

Thanks Justin. Trapping in more that one place was an act of desperation
;-p

This is what I have in the command button Click event:

****
Private Sub cmdPreview_Click()

On Error GoTo err_trap

Dim strCriteria As String
strCriteria = Me.OpenArgs & " = '" & Me.cboActionee & "'"
If Me.ogrClosed <> 3 Then strCriteria = strCriteria & " And [Closed] = " &
Me.ogrClosed
Me.Visible = False
DoCmd.OpenReport Forms(gcFrmPrint).lstReport.Column(1), acViewPreview, ,
strCriteria
DoCmd.Maximize

err_trap:
If Err.Number = 2501 Then Exit Sub

End Sub
****

I'll try your version in the meantime, but I'm wondering if some of the
other stuff I'm doing is upsetting Access. I'm basically using the same
filter form for two different reports. I'm using OpenArgs to pass the
name of the field to filter on.

Regards,
Keith.


I can't see why this would not prevent the error 2501 occuring. Normally I
have two labels Err_Handler and Exit_Handler so that the error handling code
only runs if there was an error - whereas yours will always check if the
error number is 2501 - even if no error occurred.
The Exit_Handler label always has an exit sub as the last line and it
enables me to clean up - often with an On Error Resume Next line at the
beginning of the block. You may have your own style you are happy with, but
you might like to consider the sort of approach shown below.

The only other comment I would make is that you could slow down with the
code a bit. For example:
DoCmd.OpenReport Forms(gcFrmPrint).lstReport.Column(1), acViewPreview
I might take the time to dim a variable for the report name and make sure I
get a non-zero length string before I try to open the report, but I guess
you will say that you can guarantee that gcFrmPrint will be open and
lstReport.Column(1) will return a valid non-null value.
Private Sub ShowRecordCount()

On Error GoTo Err_Handler

Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String

Set dbs = CurrentDb

strSQL = "SELECT COUNT(*) AS MyCount FROM tblMyTable"

Set rst = dbs.OpenRecordset(strSQL, dbOpenForwardOnly)

If Not rst.EOF Then
MsgBox rst.Fields("MyCount") & " record(s)"
End If

Exit_Handler:
On Error Resume Next
rst.Close
Set rst = Nothing
Set dbs = Nothing
Exit Sub

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub

Nov 13 '05 #4
"Justin Hoffman" <j@b.com> wrote in message
news:db**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...

<snip>

Many thanks again Justin, this may be the way to go :o)
Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
8445
by: ColinWard | last post by:
My previous message was blank so Im trying again. I have a button on a form which opens the Import dialogue box. This works fine except if I click on the "X" to close the form I get Run-Time Error...
1
5563
by: Bob Dydd | last post by:
Hi everyone It's me again. I have an access 2000 database with 12 landscape reports which sometimes have to be FAXED and other times printed, so I have written the following code and put it...
5
28912
by: fearblanco | last post by:
Hello - I am receiving the below error message when attempting to open a report. This database is used by approximately 20 users and only one user is having this problem (even I can't duplicate...
3
6117
by: Ed Robichaud | last post by:
I'm temporarily stumped on how to handle/suppress an error (2501) if a user cancels sending an email. I'm using DoCmd.SendObject to trigger an Outlook send window, which works OK, but if the msg...
13
4433
by: Thelma Lubkin | last post by:
I use code extensively; I probably overuse it. But I've been using error trapping very sparingly, and now I've been trapped by that. A form that works for me on the system I'm using, apparently...
33
3107
by: Anthony England | last post by:
I am considering general error handling routines and have written a sample function to look up an ID in a table. The function returns True if it can find the ID and create a recordset based on...
6
8148
by: sara | last post by:
I have a procedure to automate bringing several Excel files into our Access tables, on a daily basis. The problem is that if the user has a problem, and tries to run the import again (maybe 3...
8
2441
by: sara | last post by:
I have a report that runs fine with data. If there is no data, I have its NO Data event sending a MsgBox and cancelling the report. Then it seems I still get the 2501 message on the Open Report...
7
15899
sassy2009
by: sassy2009 | last post by:
Hello, I am running an insert query from xl spreadsheet using the DoCmd.RunSQL to insert values from the spreadsheet into the Access database. When i run this query it gives an error saying "...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7377
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7034
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5045
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1544
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.