I have customised a form to display my own error messages using:-
Private Sub Form_Error(Data Err As Integer, Response As Integer)
' If an error occurs because of duplicate data in a required field
' Display own custom error message
Const conErrDuplicate Key = 3022
Const conErrZeroKey = 3058
Select Case DataErr
Case conErrDuplicate Key
MsgBox "This Serial Number already exsists: " & Search, , "Warning Duplicate Record!"
Response = acDataErrContin ue
Case conErrZeroKey
MsgBox "You Must Enter a Serial Number before you Save the Record: " & Search, , "Warning No Serial Number!"
Response = acDataErrContin ue
Case Else
'Display a standard error message
Response = acDataErrDispla y
End Select
End Sub
In order to get my "Save" command button (not changed from Command26) to do the same i used:-
Private Sub Command26_Click ()
On Error GoTo Err_Command26_C lick
DoCmd.DoMenuIte m acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Me.[Serial Number].SetFocus
Me.Command26.Vi sible = False
Exit_Command26_ Click:
Exit Sub
Err_Command26_C lick:
If Err = 3022 Then
MsgBox "This Serial Number already exsists: " & mSearch, , "Warning Duplicate Record!"
Else
' Display the error number and the generic Access message.
MsgBox "Error #: " & Err.Number & " " & Err.Description
End If
Resume Exit_Command26_ Click
End Sub
But this only works for the one error code. Is there a way to get my "Save" command button to work with multiple error codes like my form?
PS. my programming skills are very basic at best, the above has been copied and adapted from info found on the net.
Regards
Ezzz
4 3468 ChipR 1,287
Recognized Expert Top Contributor
When you save the record, the Form's Before_Update event is automatically called, and you can use it to check for other errors, give a message, and cancel if necessary. If you set Cancel to True, you should get an error from the save record event. Here is an example straight from one of my projects. - Private Sub cmdSave_Click()
-
On Error GoTo ErrorHandler
-
-
RunCommand acCmdSaveRecord
-
-
If CurrentProject.AllForms("frmViewProjects").IsLoaded Then
-
Forms![frmViewProjects].Refresh
-
Forms![frmViewProjects].Form_Current
-
Forms![frmViewProjects].Update
-
End If
-
-
DoCmd.Close acForm, "frmEditActivity"
-
-
ExitCode:
-
Exit Sub
-
ErrorHandler:
-
If Err.number = 3022 Then
-
MsgBox "That activity already exists.", , "Duplicate Activity"
-
Else
-
HandleError Err.number, Err.Description, Me.Name & "::cmdSave_Click"
-
End If
-
Resume ExitCode
-
End Sub
-
-
-
Private Sub Form_BeforeUpdate(Cancel As Integer)
-
On Error GoTo ErrorHandler
-
Dim valid As Boolean
-
Dim strCriteria As String
-
-
valid = True
-
-
If IsNull(txtActivityNumber) Or txtActivityNumber = "" Then
-
txtActivityNumber.BorderColor = 255
-
valid = False
-
Else
-
txtActivityNumber.BorderColor = 11050647
-
End If
-
If IsNull(txtActivityTitle) Or txtActivityTitle = "" Then
-
txtActivityTitle.BorderColor = 255
-
valid = False
-
ElseIf InStr(txtActivityTitle, """") > 0 Or InStr(txtActivityTitle, ";") Then
-
MsgBox "Please avoid "" or ; characters for database compatability.", , "Input Error"
-
txtActivityTitle.BorderColor = 255
-
valid = False
-
Else
-
txtActivityTitle.BorderColor = 11050647
-
End If
-
If IsNull(cboProjectLeader) Or cboProjectLeader = "" Then
-
cboProjectLeader.BorderColor = 255
-
valid = False
-
Else
-
cboProjectLeader.BorderColor = 11050647
-
End If
-
-
If valid = False Then
-
lblError.Visible = True
-
Cancel = True
-
End If
-
-
ExitCode:
-
Exit Sub
-
ErrorHandler:
-
HandleError Err.number, Err.Description, Me.Name & "::Form_Before_Update"
-
Resume ExitCode
-
End Sub
ChipR
Thanks for the the above, but addapting it to my form is a bit beyond me?
It also looks like you are coding different entries to your form and i want to code the one entry box [Serial Number] to display multiple error messages.
I did however adapt part of it by adding an End If and then a new If Err statement see highlighted below:-
Private Sub Command26_Click ()
On Error GoTo Err_Command26_C lick
DoCmd.DoMenuIte m acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Me.[Serial Number].SetFocus
Me.Command26.Vi sible = False
Exit_Command26_ Click:
Exit Sub
Err_Command26_C lick:
If Err = 3022 Then
MsgBox "This Serial Number already exsists: " & Search, , "Warning Duplicate Record!" End If
If Err = 3058 Then
MsgBox "You Must Enter a Serial Number before you Save the Record: " & Search, , "Warning No Serial Number!"
Else
' Display the error number and the generic Access message.
MsgBox "Error #: " & Err.Number & " " & Err.Description
End If
Resume Exit_Command26_ Click
End Sub
This almost solves my problem in that it now displayes the error messages i want it to but it also displayes the default error message for 3022 as well. Any ideas??
Regards
Ezzz
Please remember to use the code tags [code][/code] around your code. It will make it much easier to read.
What you need is to use either a Select statement: - Select Case Err.Number
-
Case 3022
-
MsgBox "This Serial Number already exsists: " & Search, , "Warning Duplicate Record!"
-
-
Case 3058
-
MsgBox "You Must Enter a Serial Number before you Save the Record: " & Search, , "Warning No Serial Number!"
-
-
Case Else
-
'Display the error number and the generic Access message.
-
MsgBox "Error #: " & Err.Number & " " & Err.Description
-
-
End Select
Another option is to use the elseif statement - If Err.Number= 3022 Then
-
MsgBox "This Serial Number already exsists: " & Search, , "Warning Duplicate Record!"
-
-
ElseIf Err.Number = 3058 Then
-
MsgBox "You Must Enter a Serial Number before you Save the Record: " & Search, , "Warning No Serial Number!"
-
-
Else
-
'Display the error number and the generic Access message.
-
MsgBox "Error #: " & Err.Number & " " & Err.Description
-
End If
A more general suggestion to help yourself, is to give your buttons a sound name.
Some people like to use for command buttons the prefix cmd (example cmd_Save or cmdSave), I myself prefix all my buttons with btn, btn_Save for example.
Thats it the ElseIf statement works a treat many thanks.
Ezzz.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Mr. Magoo |
last post by:
I'm working with imaplib. I'm trying to flag (or move or copy - anything
that takes a message_set as an argument) a bunch of messages with one
command and am having trouble.
===
def check_error(typ, data):
if (typ != 'OK'):
print typ
print data
|
by: dav |
last post by:
Hi All,
I'm a bit new to VBA and wanted to know is there any way you can format the
command button? i.e make it a slightly different shape (rounded edges) and
things like that.
cheers
Dav
|
by: bjbounce2002 |
last post by:
Hello,
I am using forms with command buttons to close form or run action
queries. The error messages such as "Null value in required field" or
"duplicate value in primary key" are suppressed. The error messages
appear when runnign the apend query manually or when closing the form
using X, but not when using command buttons.
Does anyone know how can the messages be displayed when using command
|
by: mark |
last post by:
I have an asp.net ecommerce web application on a remote web server.
I'm using an Access database on the back end. I've notice a few
strange things. When I mimic an multiple user environment by surfin
it in multiple browsers simultaneously the site generates a generic
runtime error after awhile. I'm thinking this has something to do
with my access database and multiple connections. I'm using forms
authentication with a login page. Is...
|
by: James Radke |
last post by:
Hello,
I have a multithreaded windows NT service application (vb.net 2003) that I
am working on (my first one), which reads a message queue and creates
multiple threads to perform the processing for long running reports. When
the processing is complete it uses crystal reports to load a template file,
populate it, and then export it to a PDF.
It works fine so far....
| |
by: Brian Tkatch |
last post by:
Server: DB2/SUN 8.1.6
Client: DB2 Connect Personal Edition (No 11)
<URL:ftp://ftp.software.ibm.com/ps/products/db2/fixes2/english-us/db2winIA32v8/fixpak/FP11_WR21365/FP11_WR21365_CONPE.exe>
Uninstalled old version, installed new version, and am now trying to
use the CLP.
<<<<<<<<<<<<
For more detailed help, refer to the Online Reference Manual.
|
by: Chris Curvey |
last post by:
Hi all,
I've apparently tied myself up a bit using the logging package.
In my project, I have a core set of model and controller classes that
set up their logging using logging.fileConfig(). So far, so good.
But I use these core classes from a bunch of different places.
Sometimes from within a CherryPy server, sometimes batch jobs run from
a command line, sometimes from Windows services (also written in
|
by: xian2 |
last post by:
Hi All,
I have been using this guide http://www.compasscomputing.co.uk/code/AcceesReportsToPDFandEmail.htm to create a command button that automatically saves and e-mails your report and have tried to edit the code, as below (the original code is on his website) but get a load of error messages.
There are only a few bits that need editing (about 6 or 7 little bits) but I still get loads of error messages and if anyone can help, I would...
|
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...
|
by: Tom van Stiphout |
last post by:
On Thu, 30 Oct 2008 11:04:44 GMT, "JOHNNY OUTING" <outingjr@att.net>
wrote:
You managed to violate several netiquette rules in one post. Please
review http://www.mvps.org/access/netiquette.htm
This is a text-only newsgroup (you could have captured the error
message with Ctrl+C), and if you can't be bothered to check back for
messages, why would we make the effort to answer in the first place?
RunCode is designed to call a public...
|
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: 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...
|
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: 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...
|
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...
| |