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.Setwarni ngs 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?
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.Setwarni ngs 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?
Code:
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 [QUOTE] <-- this is not working[/QUOTE]
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
Comment