473,320 Members | 2,104 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,320 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 22665
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...

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.