473,405 Members | 2,334 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,405 software developers and data experts.

Using Custom Error Messages

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 2717
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
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 Expert 1GB
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
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 Expert 8TB
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
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...
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...
6
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...
17
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...
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...
7
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...
2
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...
1
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...
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...
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: 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
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,...
0
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...
0
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...
0
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...

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.