473,378 Members | 1,527 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

How do you prevent access from showing error dialog box (Runtime error 2501).

I keep on getting the same error message and I don't know how to either solve the problem or prevent it from showing the error. I have set up a switchboard item that opens a report. When the report opens it will call a form so that the user can change parameters in the report and filter the information before the report is generated see below.


Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Open(Cancel As Integer)
  2. DoCmd.OpenForm "CostCodeFilter", , , , acFormAdd, 3
  3.  
  4. 'Triggered object in the form will let the program know if the user has cancelled the report.
  5. If Reports![Cost Code Stats].Controls("Label14").Visible = False Then   
  6.     Cancel = True
  7. End If
  8. End Sub
  9.  
If the user closes the filter box it will cancel the report generation but for some reason it always spits out the same error message.

I have tried using error handling in the code but the problem is that the error is generated outside of the open event and the error handling is not triggered.

Thanks for help.
May 30 '12 #1

✓ answered by TheSmileyCoder

The error is being raised by line 2:
Expand|Select|Wrap|Line Numbers
  1. Function CCS_Run()
  2.   DoCmd.OpenReport "Cost Code Stats", acViewPreview
  3. End Function
  4.  
when the report is cancelled.

Check for the error, and ignore it.

Expand|Select|Wrap|Line Numbers
  1. Function CCS_Run()
  2.   On Error Goto ErrHandler
  3.   DoCmd.OpenReport "Cost Code Stats", acViewPreview
  4.  
  5. ExitFunction:
  6.   Exit Function
  7.  
  8. ErrHandler:
  9.   If Err.Number=2501 then
  10.     'User cancelled report, ignore and exit
  11.     Resume ExitFunction
  12.   Else
  13.     Msgbox Err.Number & " - " & err.Description
  14.     Resume ExitFunction
  15.   End If
  16. End Function
  17.  

3 8071
Just to clarify..

The switch board runs prompts the function CCS_Run

Expand|Select|Wrap|Line Numbers
  1. Function CCS_Run()
  2. DoCmd.OpenReport "Cost Code Stats", acViewPreview
  3. End Function
That function loads the the report which has an open event

Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Open(Cancel As Integer)
  2.  
  3. DoCmd.OpenForm "CostCodeFilter", , , , acFormAdd, 3
  4. 'Cost code filter will load a form that allows the user to filter the report.
  5.  
  6. If Reports![Cost Code Stats].Controls("Label14").Visible = False Then: Cancel = True
  7.  
  8. End Sub
I found that if I open the report from database instead of through the switch board I do not get the error message otherwise the error will come up.

Does it create problems if I have nested DoCmd.Open commands?
May 30 '12 #2
The answer is yes it does create problems. There has to be an error handle in the function CCS_Run to catch the event that the report has been cancelled.
May 30 '12 #3
TheSmileyCoder
2,322 Expert Mod 2GB
The error is being raised by line 2:
Expand|Select|Wrap|Line Numbers
  1. Function CCS_Run()
  2.   DoCmd.OpenReport "Cost Code Stats", acViewPreview
  3. End Function
  4.  
when the report is cancelled.

Check for the error, and ignore it.

Expand|Select|Wrap|Line Numbers
  1. Function CCS_Run()
  2.   On Error Goto ErrHandler
  3.   DoCmd.OpenReport "Cost Code Stats", acViewPreview
  4.  
  5. ExitFunction:
  6.   Exit Function
  7.  
  8. ErrHandler:
  9.   If Err.Number=2501 then
  10.     'User cancelled report, ignore and exit
  11.     Resume ExitFunction
  12.   Else
  13.     Msgbox Err.Number & " - " & err.Description
  14.     Resume ExitFunction
  15.   End If
  16. End Function
  17.  
May 30 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Tony Johansson | last post by:
Hello Experts! I reading a book called programming with design pattern revealed by Tomasz Muldner and here I read something that sound strange. "Exception are divided into logic errors and...
7
by: Yongsub Eric Shin | last post by:
Hi. I'm just a beginner in ASP.Net. I started writing codes and I keep on getting this Runtime Error page, where it says "Description: An application error occurred on the server. The current...
0
by: GHS | last post by:
I'm writing code to parse a specific website and decided to use MSHTML to help (instead of regular expressions). The parsing code is complete - looks very nice if I say so myself. :-) The...
7
by: John | last post by:
Hi Everyone, I'm having this extremely annoying problem with Internet Explorer 6, giving me an error message saying "unknown runtime error" whenever I try to alter the contents of a <divelement...
3
by: Peachstone | last post by:
I'm using Windows XP and MS Access 2002. I am trying to write code in VB which is attached to a text control on a form called "Scripture1". I have another text control on the same form called...
2
by: suneel pandey | last post by:
when I open aspx page from html this error occur Runtime Error Description: An application error occurred on the server. The current custom error settings for this application prevent the...
20
by: vjayis | last post by:
hi when i m trying to fetch data from one page to another page using ajax, i get an error message in IE., but it runs well in firefox., could anyone help me., here is my javascript code., ...
1
by: kickergirl | last post by:
I recently created a database in Access 2000 that has been distributed to multiple people using various versions of Access. Each person is using it as a standalone database. The database has...
16
by: rudivs | last post by:
I would like to do data validation in the BeforeUpdate procedure, but Access gives me a runtime error when I try to do this: An example of what I am trying to do is as follows: Private Sub...
3
by: ShyamKrishnegowda | last post by:
We are writing test scripts to our product. In one of the script we are facing an issue. This test script will create a COM component and executes the following function. O1 and O2 are out...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.