473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,386 developers and data experts.

Custom Error Messages

ADezii
8,834 Expert 8TB
One of the most frequently asked questions here at TheScripts is: Can I replace Standard Access Error Messages with my own? The answer is yes under certain circumstances and it involves the placement of code in a Form's Error() Event and setting a specific Parameter to either 1 of 2 values. Many Errors occur while your Form is active and it is within this context that you can replace the standard Access behavior when these Errors occur with behavior that is a little friendlier to the User. As previously stated, by attaching code to the Error() Event of a Form, your Procedure will be called whenever a Trappable Error occurs while the Form is running.

The Syntax for the call is as follows:
Sub Form_Error(DataErr As Integer, Response As Integer)
__1. DataErr - contains the Error Number for the Error that just occurred.
__2. Response - Allows you to specify how you want Access to handle the Error. If your code handles the Error to your satisfaction and you don't want Access to intervene or display its own message, place the value acDataErrContinue in Response. If you want Acces to display its own Error Message, place acDataErrDisplay in Response.

The following code traps 4 Errors that might pop up. In each case, the procedure replaces the Standard Access Error Message with its own. If an Error occurs that it hadn't planned on, the Procedure just passes the responsibility back to Access:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Error(DataErr As Integer, Response As Integer)
  2. Const conErrDataValidation = 3317
  3. Const conErrDataType = 2113
  4. Const conErrDuplicateKey = 3022
  5. Const conErrNullKey = 3058
  6.  
  7. Select Case DataErr
  8.    Case conErrDataValidation, conErrDataType
  9.       'your Error Message here
  10.       Response = acDataErrContinue  
  11.    Case conErrDuplicateKey
  12.       'your Error Message here
  13.       Response = acDataErrContinue   
  14.    Case conErrNullKey
  15.       'your Error Message here
  16.       Response = acDataErrContinue   
  17.    Case Else
  18.       ' It's an unexpected error.  Let Access handle it.
  19.        Response = acDataErrDisplay
  20. End Select
  21. End Sub 
Mar 24 '07 #1
7 22683
Denburt
1,356 Expert 1GB
Sweeeet!!! Thanks I should have implemented somthing along these lines YEARS ago....Will do so immediately, upon returning to work of course.
Mar 25 '07 #2
NeoPa
32,556 Expert Mod 16PB
Sweeeet!!! Thanks I should have implemented somthing along these lines YEARS ago....Will do so immediately, upon returning to work of course.
Echo!
Nice one ADezii.
Mar 27 '07 #3
ADezii
8,834 Expert 8TB
Echo!
Nice one ADezii.
Thanks, NeoPa.
Mar 28 '07 #4
Geneman
17
I'll take that error code suggestion one step further.

Using your code still only gives the user a small obscure message that is not nicely formatted. In many cases all they need is this but, there are some cases when a more detailed explanation is needed.

In this case, I propose a table of error codes and explanations.

Thus using your code or a variation thereof.....you could OnERR open a POPUP
form and have it access a record in the Error Code Table.

Then in creating that table use your error code numbers as one field and the explanations as the next field.

The POPUP form would only show the second field, nicely formatted.
Example: Error 2003

You have hit the enter key.
You need to hit the Tab Key.
When at first you don't suceed.
Try Try Again.

Then below this place a button that closes the form labeled
TRY AGAIN

This error message not only tells them what they did wrong,
It tells them how to fix it!
May 4 '07 #5
NeoPa
32,556 Expert Mod 16PB
I did something similar once with an error table (I still use). I included the type of continue allowed (You can retry with an ODBC timeout type error for instance). The problem I found was that you never get told when Microsoft change the error list.
May 4 '07 #6
ADezii
8,834 Expert 8TB
I did something similar once with an error table (I still use). I included the type of continue allowed (You can retry with an ODBC timeout type error for instance). The problem I found was that you never get told when Microsoft change the error list.
Good point, Neo. It's not like they're Intrinsic Constants.
May 4 '07 #7
hyperpau
184 Expert 100+
Hi,
I would like to contribute to this. :)
Information courtesy of FishVal.

http://bytes.com/forum/thread830828-custom+error+messages.html
Aug 18 '08 #8

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

Similar topics

3
by: Mark Metzner | last post by:
We currently have custom error logging setup on all of our websites. We have IIS setup to redirect to our custom 500-100.asp page which logs the error to a database and then redirects to a...
16
by: Bret Pehrson | last post by:
I've converted a non-trivial C++ library to managed, and get the following unhelpful linker error: Assignment.obj : error LNK2022: metadata operation failed (80131195) : Custom attributes are...
4
by: LhK-Soft | last post by:
Hi, I'm active in VC++ for several years now, so I know some things (I think). Using MS-Access I store a db with lots of entries and uses the VBA techniques to export those data to e.g. HTML, XML...
1
by: Tamas Demjen | last post by:
I started to experiment with VC++ 2005 Beta1. So far everything went fine, and already have a working project, but soon I realized that the compiler was ancient (not supporting half of the C++/CLI...
8
by: pmud | last post by:
Hi, I am using a compare validator in asp.net application(c# code). This Custom validator is used for comparing a value enterd by the user against the primary key in the SQL database. IF the...
3
by: Brad Wood | last post by:
If I add my own section to my Web.Config file of my (2.0) web service project (and refer to it by adding a "section" sub-element to a "configSections" element, I then get information messages...
8
by: g_man | last post by:
I am trying trap Runtime error 3022 (duplicates) in the click event of a command button that closes the form. I have code in the Form_Error event that does a good job of providing a more meaningful...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
1
by: asharda | last post by:
I have a custom property grid. I am using custom property grid as I do not want the error messages that the propertygrid shows when abphabets are entered in interger fields. The custom property...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
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...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.