473,657 Members | 2,627 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using Custom Error Messages

6 New Member
I have created a form that captures Capital Project Request data for review. After the reviewer has made their decision as to approve or deny the project request, they click an approval button or a denial button. When the button is clicked, an append query runs and writes the data to the appropriate table. I have the project ID set as the primary key and the project ID field is set to not allow duplicates. This process is working correctly, but I want to replace the standard access message with a custom message telling the reviewer the project has already been saved and that duplicates are not allowed. I thought I found the code that would enable me to add the custom message but I have not been able to get a custom message of any type to appear. The code I have written is as follows:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Approve_Click()
  2. On Error GoTo Err_Approve_Click
  3.  
  4.     DoCmd.GoToRecord , , acNewRec
  5.  
  6.     Dim stDocName As String
  7.  
  8.     stDocName = "Qry_Final Capital Budget Approval"
  9.     DoCmd.OpenQuery stDocName, acNormal, acEdit
  10.  
  11.  
  12. Exit_Approve_Click:
  13.     Exit Sub
  14.  
  15. Err_Approve_Click:
  16.    Select Case Err.Number
  17.  
  18.     Case 3022
  19.         MsgBox "Data has already been saved. Duplicates not allowed."
  20.  
  21.     Case Else
  22.         MsgBox "This is an unexpected error.  Please report this to the administrator."
  23. End Select
  24. Response = acDataErrContinue
  25. Resume Exit_Err_Approve_Click
  26.  
  27.  
  28. End Sub
Any help would be appreciated as my knowledge of VB is very limited and I have taken most of my code from samples and online fourms.
Jan 20 '09 #1
5 2763
mandanarchi
90 New Member
Try changing this line
Expand|Select|Wrap|Line Numbers
  1. Select Case Err.Number
to this
Expand|Select|Wrap|Line Numbers
  1. Select Case Err
Jan 20 '09 #2
dlblack
6 New Member
Mandanarchi,
I made the suggested change, but the error message displaying is still the default message. Any other suggestions would be appreciated.
Jan 20 '09 #3
ChipR
1,287 Recognized Expert Top Contributor
Personally I do a DLookup on the table's primary key with the entered data and see if it returns anything other than null. If so, that data is already in the table, and I give a message and exit the function. I don't know whether others find this preferable to generating an error.
Also, your Resume label doesn't match anything.
Jan 20 '09 #4
dlblack
6 New Member
Chip,
Thanks for the tip. I will try implementing the Dlookup to see if this solves my issue.
Jan 22 '09 #5
ADezii
8,834 Recognized Expert Expert
You are simply writing your code in the wrong Event. To specifically trap Errors generated within the context of a Form, use a combination of the Form's Error() Event and the Response Argument. The following demo should point you in the right direction:
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Form_Error(DataErr As Integer, Response As Integer)
  3. Const conNO_ERROR = 0
  4. Const conERR_DUPLICATE_KEY = 3022
  5.  
  6. Select Case DataErr
  7.   Case conNO_ERROR              'do nothing
  8.   Case conERR_DUPLICATE_KEY     'Duplicate Value in Index/Key
  9.     MsgBox "This Record duplicates the Primary, try another Value", _
  10.             vbExclamation, "Duplicate Entry"
  11.   Case Else                     'Unknown
  12.     MsgBox "Unspecified Error", vbExclamation, "Error in Form_Error()"
  13.   End Select
  14.     Response = acDataErrContinue        'suppress Access's built in Error Message
  15. End Sub
  16.  
Jan 23 '09 #6

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

Similar topics

5
2672
by: Bud Zielinski | last post by:
understand that through IIS you can implement custom error messages, but since we are in hosted environment, we need to implement custom error pages using ASP. Is this possible and could someone point us in the right direction on how to do this ? Thanks Bud
3
4174
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...
6
4607
by: radnoraj | last post by:
Hi, I am sucessfull in redirecting console output to a file. but in this case nothing is displayed on the console, cout output is written to file without display. how do write the output to console as well as to file, my code is as below, ======================================================================= #include <iostream.h> #include<ostream> #include<sstream>
17
7452
by: Steve Jorgensen | last post by:
If you've ever employed custom error numbers and messages in you programs, you've probably ended up with code similar to what I've ended up with in the past something like... <code> public Const xyzcErrNumBase As Long = 500 Public Const xyzcErrNumHeyDontDoThat = xyzcErrNumBase + 1 Public Const xyzcErrTxtHeyDontDoThat = "Hey! Don't do that!"
1
4204
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...
7
5123
by: Nilesh | last post by:
I am using background-image attribute in a CSS file and linking the CSS file to aspx page. But strangly, background-image attribute is not working for relative URL. e.g. If I apply following css ..navbar-background { background-image: url(images/menubar.gif); } the image is not appearing on the page. It seems that IE is picking
2
3724
by: Barbara Alderton | last post by:
I setup some standard Required Field Validation controls and one Custom validation control on an ASP.NET page (within a user control) to validate text entry. I also setup a Summary Control to post all the messages to a message box (ShowMessageBox=true). The required field validation error messages show up in the summary just fine but I can't get the custom validation message to show up if invalid. So far I have the summary control...
1
1344
by: Jacob | last post by:
Hi, How can i store custom error messages, can i store it in a resource file , like ErMsgs.Resx. if i store it in a .resx file, can i modify it without recompiling, if so how can i change it without recompiling?? thanks in advance .
3
5553
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?
0
8392
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
8305
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
8825
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...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7324
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...
0
5632
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
4151
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...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1611
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.