473,909 Members | 4,177 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Custom Error Messages

ADezii
8,834 Recognized Expert Expert
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(Data Err 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 acDataErrContin ue in Response. If you want Acces to display its own Error Message, place acDataErrDispla y 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 22855
Denburt
1,356 Recognized Expert Top Contributor
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,584 Recognized Expert Moderator MVP
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 Recognized Expert Expert
Echo!
Nice one ADezii.
Thanks, NeoPa.
Mar 28 '07 #4
Geneman
17 New Member
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,584 Recognized Expert Moderator MVP
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 Recognized Expert Expert
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 Recognized Expert New Member
Hi,
I would like to contribute to this. :)
Information courtesy of FishVal.

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

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

Similar topics

3
4187
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 friendly error message page. Last week we were working on a pretty troublesome error on our intranet site and noticed huge discrepencies between the IIS Log and our error log database. On this particular day for this particular site, the IIS Log has...
16
9311
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 not consistent: (0x0c0001a5). Display.obj : error LNK2022: metadata operation failed (80131195) : Custom attributes are not consistent: (0x0c000108). The help for LNK2022 is completely useless:
4
1950
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 and other kind of data. I'm using MS-VC++6.0-Enterprise (with sp6) at NT4-Workstation (sp6a) and MS-Access97 (from MS-Office97). Reason that I won't upgrade to latest Office/VisualStudio is that I must ensure that any application I develop still...
1
4216
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 standard). So I downloaded the VC++ 2005 Tools Refresh (http://tinyurl.com/5mdq2). After that I tried to do a full rebuild, but my project wouldn't link anymore. I get the following errors: MSVCMRTD.lib(mstartup.obj) : error LNK2022: metadata...
8
7842
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 VALUE ENTERED BY THE USER EXISTS IN THE DB , then THE ERROR MESSAGE OF THE COMPARE VALIDATOR SHOULD BE DISPLAYED. For this, I used the reference artiicle "http://msdn.microsoft.com/library/default.asp?url=/library/en-...
3
5570
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 ("Could not find schema information for the element"...) for every custom element and attribute in my custom section when I build my project. What should I do to properly dispose of these messages? Surely I shouldn't have to create a schema?
8
13123
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 error message than the default. It works in every situation except when the user clicks the close button. I am using Me.Dirty=False to force a save but if there are duplicates I just get the standard Runtime 3022 error message. I am wondering...
2
19516
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 will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
1
4404
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 grid doesn't show colloections i.e. if I have a List<Objectthen the Collection is shown but when I click on the "..." button next to it nothing comes up. If I say CustomPropertyGrid p = new CustomPropertyGrid(); p.SelectedObject = new...
0
2897
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 will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
0
9877
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10919
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...
0
10538
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9725
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8097
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
7248
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
5938
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
6138
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4336
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.