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: - Private Sub Approve_Click()
-
On Error GoTo Err_Approve_Click
-
-
DoCmd.GoToRecord , , acNewRec
-
-
Dim stDocName As String
-
-
stDocName = "Qry_Final Capital Budget Approval"
-
DoCmd.OpenQuery stDocName, acNormal, acEdit
-
-
-
Exit_Approve_Click:
-
Exit Sub
-
-
Err_Approve_Click:
-
Select Case Err.Number
-
-
Case 3022
-
MsgBox "Data has already been saved. Duplicates not allowed."
-
-
Case Else
-
MsgBox "This is an unexpected error. Please report this to the administrator."
-
End Select
-
Response = acDataErrContinue
-
Resume Exit_Err_Approve_Click
-
-
-
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.
5 2763
Try changing this line
to this
Mandanarchi,
I made the suggested change, but the error message displaying is still the default message. Any other suggestions would be appreciated.
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.
Chip,
Thanks for the tip. I will try implementing the Dlookup to see if this solves my issue.
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: -
-
Private Sub Form_Error(DataErr As Integer, Response As Integer)
-
Const conNO_ERROR = 0
-
Const conERR_DUPLICATE_KEY = 3022
-
-
Select Case DataErr
-
Case conNO_ERROR 'do nothing
-
Case conERR_DUPLICATE_KEY 'Duplicate Value in Index/Key
-
MsgBox "This Record duplicates the Primary, try another Value", _
-
vbExclamation, "Duplicate Entry"
-
Case Else 'Unknown
-
MsgBox "Unspecified Error", vbExclamation, "Error in Form_Error()"
-
End Select
-
Response = acDataErrContinue 'suppress Access's built in Error Message
-
End Sub
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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...
|
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>
|
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!"
|
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...
| |
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
|
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...
|
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 .
|
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?
|
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...
|
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,...
| |
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...
|
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,...
|
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...
|
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();...
|
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...
|
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
| |
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...
| |