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 9310
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.
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)
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,534
Expert Mod 16PB
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: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |