Hi,
I am trying to do error handling during insert in MS Access 2002 (OS: MS XP)
The problem is that when a duplicate record is added for the primary key field or a null value included in a unique filed, an error appears:
"Microsoft Access cannot append all the records in the append query!"
What I want is to suppress this message and display my own message, but both this message and mine one comes while I do the error handling.
Please suggest. I have included the code. Using "Docmd.Setwarnings false" suppresses the display of both the above message as well as my message -- it actually doesn't do the error handling.
Also, where can I find the list of errors in Access and their error numbers? -
Private Sub cmdsave_Click()
-
-
On Error GoTo errmsg
-
Form.Requery
-
-
DoCmd.RunSQL "INSERT INTO members ( IDNo, Name, MemberType, Designation, Address, " _
-
& "Citizenship, CitizenNo, FirmName ) " _
-
& "SELECT tmpmembers.IDNo, tmpmembers.Name, tmpmembers.MemberType, tmpmembers.Designation, " _
-
& "tmpmembers.Address, tmpmembers.Citizenship, tmpmembers.CitizenNo, tmpmembers.FirmName " _
-
& "FROM tmpmembers"
-
-
exit_cmdsave:
-
Exit Sub
-
-
errmsg:
-
-
If Err = 3022 Then
-
-
<-- this is not working
-
-
-
MsgBox "The IDNO already exists. Please type another one!", vbOKOnly, "Duplicate ID Error"
-
-
ElseIf Err = 3058 Then
-
-
MsgBox "IDNO cannot contain Blank!", vbOKOnly, "Blank ID!"
-
-
Else
-
MsgBox Err.Number & ":" & " " & Err.Description, , "Error!"
-
-
End If
-
Resume exit_cmdsave
-
-
End Sub
-
4 9423
Hi,
I am trying to do error handling during insert in MS Access 2002 (OS: MS XP)
The problem is that when a duplicate record is added for the primary key field or a null value included in a unique filed, an error appears:
"Microsoft Access cannot append all the records in the append query!"
What I want is to suppress this message and display my own message, but both this message and mine one comes while I do the error handling.
Please suggest. I have included the code. Using "Docmd.Setwarnings false" suppresses the display of both the above message as well as my message -- it actually doesn't do the error handling.
Also, where can I find the list of errors in Access and their error numbers? -
Private Sub cmdsave_Click()
-
-
On Error GoTo errmsg
-
Form.Requery
-
-
DoCmd.RunSQL "INSERT INTO members ( IDNo, Name, MemberType, Designation, Address, " _
-
& "Citizenship, CitizenNo, FirmName ) " _
-
& "SELECT tmpmembers.IDNo, tmpmembers.Name, tmpmembers.MemberType, tmpmembers.Designation, " _
-
& "tmpmembers.Address, tmpmembers.Citizenship, tmpmembers.CitizenNo, tmpmembers.FirmName " _
-
& "FROM tmpmembers"
-
-
exit_cmdsave:
-
Exit Sub
-
-
errmsg:
-
-
If Err = 3022 Then
-
-
MsgBox "The IDNO already exists. Please type another one!", vbOKOnly, "Duplicate ID Error"
-
-
ElseIf Err = 3058 Then
-
-
MsgBox "IDNO cannot contain Blank!", vbOKOnly, "Blank ID!"
-
-
Else
-
MsgBox Err.Number & ":" & " " & Err.Description, , "Error!"
-
-
End If
-
Resume exit_cmdsave
-
-
End Sub
-
I think the error number for the duplicate IDNO is not 3022 it's 2501.
I tested it on my machine and it worked very well.
Note that when you are promted that an error occured and you have to choose between yes no and Help , you have to choose No.
nico5038 3,080
Recognized Expert Specialist
Error messages may differ depending on the installed Access/JetEngine version.
Best to do a check for an existing ID before issuing the INSERT.
You could use a DLOOKUP like:
IF IsNull(DLOOKUP("IDNo","members","IDNo=" & Me.IDNo)) then
This assumes that the IDNo is a field on your form.
Nic;o)
ADezii 8,834
Recognized Expert Expert
Hi,
I am trying to do error handling during insert in MS Access 2002 (OS: MS XP)
The problem is that when a duplicate record is added for the primary key field or a null value included in a unique filed, an error appears:
"Microsoft Access cannot append all the records in the append query!"
What I want is to suppress this message and display my own message, but both this message and mine one comes while I do the error handling.
Please suggest. I have included the code. Using "Docmd.Setwarnings false" suppresses the display of both the above message as well as my message -- it actually doesn't do the error handling.
Also, where can I find the list of errors in Access and their error numbers? -
Private Sub cmdsave_Click()
-
-
On Error GoTo errmsg
-
Form.Requery
-
-
DoCmd.RunSQL "INSERT INTO members ( IDNo, Name, MemberType, Designation, Address, " _
-
& "Citizenship, CitizenNo, FirmName ) " _
-
& "SELECT tmpmembers.IDNo, tmpmembers.Name, tmpmembers.MemberType, tmpmembers.Designation, " _
-
& "tmpmembers.Address, tmpmembers.Citizenship, tmpmembers.CitizenNo, tmpmembers.FirmName " _
-
& "FROM tmpmembers"
-
-
exit_cmdsave:
-
Exit Sub
-
-
errmsg:
-
-
If Err = 3022 Then
-
-
MsgBox "The IDNO already exists. Please type another one!", vbOKOnly, "Duplicate ID Error"
-
-
ElseIf Err = 3058 Then
-
-
MsgBox "IDNO cannot contain Blank!", vbOKOnly, "Blank ID!"
-
-
Else
-
MsgBox Err.Number & ":" & " " & Err.Description, , "Error!"
-
-
End If
-
Resume exit_cmdsave
-
-
End Sub
-
There have been several Posts relating to this very Topic. To suppress the standard Access Error Message and display your own, custom Error Message, you need to write code in the Form's Error() Event, trap the specific Error (which Err.Number will return), and set the acDataErrContinue CONSTANT: - Private Sub Form_Error(DataErr As Integer, Response As Integer)
-
If DataErr = XXXX Then 'Trap specific Error here
-
MsgBox "Your specific Error Message", vbExclamation, "Blah, Blah, Blah"
-
Response = acDataErrContionue 'do not display the Default Error Message
-
End If
-
End Sub
NeoPa 32,556
Recognized Expert Moderator MVP
That's good stuff ADezii, but I think a better solution is to check before adding the record (As per Nico's post #2).
Error handling is good, but relying on it in the logic of the code is not generally to be recommended IMHO. If for no other reason than the error handling settings on an individual PC may differ from those expected. That and simplicity of code.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Wayno |
last post by:
My php logs are coming up empty. I have done all I can think of, and
all that made sense to me. Can someone take a look at my php.ini
please and tell me what you think may be the problem.
I...
|
by: Sean Abrahams |
last post by:
The following is a reprint of a message I sent to the tutor list a long
time ago, that I haven't gotten around to discussing with anyone else
and failed to hear a reply on the tutor list. Hoping...
|
by: dmiller23462 |
last post by:
Hey guys....
I put an error-handling in my page and have it posted at the complete
end of the code, see below(when people were putting in 's I was
getting the delimiter errors). Great, I...
|
by: Thelma Lubkin |
last post by:
I use code extensively; I probably overuse it. But I've been using
error trapping very sparingly, and now I've been trapped by that.
A form that works for me on the system I'm using, apparently...
|
by: TD |
last post by:
This is the code under a command button -
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.BackColor <> RGB(255, 255, 255) Then
ctl.BackColor = RGB(255, 255, 255)
End If
Next ctl
|
by: michaeltorus |
last post by:
Hi
I'm currently designing a new web application in .Net. I've pretty covered everything, apart from error handling.
There seems to be a few different way to do this, but something I've read...
|
by: James Radke |
last post by:
Hello,
I am looking for guidance on best practices to incorporate effective and complete error handling in an application written in VB.NET. If I have the following function in a class module...
|
by: jeffc226 |
last post by:
I'm interested in an idiom for handling errors in functions without
using traditional nested ifs, because I think that can be very awkward
and difficult to maintain, when the number of error checks...
|
by: mbenedict |
last post by:
I am rather new at this code and am attempting to modify existing code to use clob datatypes, which I have never used before. The database tables have been set up for clob data. When trying to use...
|
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...
|
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,...
|
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,...
|
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...
|
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,...
|
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: 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...
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |