473,850 Members | 2,066 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.OpenRepor t Forms(gcFrmPrin t).lstReport.Co lumn(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 9456
"Keith" <ke*********@ba eAWAYWITHITsyst ems.com> wrote in message
news:42******** **@glkas0286.gr eenlnk.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.OpenRepor t Forms(gcFrmPrin t).lstReport.Co lumn(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(C ancel As Integer)
MsgBox "No matching records"
Cancel = True
End Sub
Private Sub cmdReport_Click ()

On Error GoTo Err_Handler

DoCmd.OpenRepor t "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_Clic k()

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.OpenRepor t Forms(gcFrmPrin t).lstReport.Co lumn(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*********@ba eAWAYWITHITsyst ems.com> wrote in message
news:42******** **@glkas0286.gr eenlnk.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_Clic k()

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.OpenRepor t Forms(gcFrmPrin t).lstReport.Co lumn(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.OpenRepor t Forms(gcFrmPrin t).lstReport.Co lumn(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.Colum n(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.OpenRecords et(strSQL, dbOpenForwardOn ly)

If Not rst.EOF Then
MsgBox rst.Fields("MyC ount") & " 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
8461
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 2501: the DoMenuItem was Cancelled". How can I trap this error so that it doesn't display but simply closes the form? Thanks Colin
1
5608
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 in a module to bring up the print dialog: Public Function PrintAccess()
5
28975
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 this error on my own PC). The command being used is DoCmd.OpenReport "rptSYS_ChangeInARDaily", acViewPreview OR DoCmd.OpenReport "rptSYS_ChangeInARDaily", acViewPreview, , "Collector=
3
6139
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 is cancelled (not sent) then a VB runtime error msg appears (#2501) that I would like to either hide or deal with. -Ed
13
4497
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 runs into problems on the system where it will actually be used, and since I used so little error-trapping it dies very ungracefully. I will of course try to fix whatever is causing the error and add error-trapping to the functions where the...
33
3172
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 that ID, otherwise it returns false. **I am not looking for comments on the usefulness of this function - it is only to demonstrate error handling** There are three versions of this code. David Fenton says under the earlier thread "DAO...
6
8213
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 files imported then there was a data problem and they want to re-import after fixing the problem), I can't get the Error handling to fire if the user is attempting to import duplicate key records. Message when I try to import records already on...
8
2460
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 command, even though I have the code to trap Err 2501 (from many postings - all looked the same to me) on the button the user pressed to get the report. I never see the code going to my error handling on the button. If I debug, I am in an...
7
15942
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 " Run-time error 2501 RunSQL action was cancelled". I know why this is happening and it's because of the message box that appears when an action query is run in Access which asks for a confirmation from the user "yes" or "no" buttons. But when i run the...
0
9895
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11011
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10666
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7899
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7071
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5735
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5929
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4140
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3178
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.