err.number = 0

  • Thread starter ragtopcaddy via AccessMonster.com
  • Start date
R

ragtopcaddy via AccessMonster.com

I am trying to replace the Access msg (with no runtime error # in the dialog
box):

"The changes you requested to the table were not successful because they
would create duplicate values in the index, primary key, or relationship.
Change the data in the field or fields that contain duplicate data, remove
the index, or redefine the index to permit duplicate entries and try again."

with my own using the following code:

Private Sub Form_Error(DataErr As Integer, Response As Integer)
If Err.Number = 3022 Then
Response = acDataErrContinue
MsgBox "You tried to enter a pair of indices that are already represented
in the recordset." & vbCrLf & _
"Please OK this msg box and hit the ""Esc"" key to clear the error.
" & vbCrLf & _
"You can then find and change the MR Level for the indices or add
2 different indices.", _
vbOKOnly + vbCritical, "Duplicate Record"
End If
End Sub

If it was working, I wouldn't be posting, so what gives? Err.Number = 0 when
the code runs, so nothing happens and the same old access msg is displayed.

Thanks,

Bill

--
Bill Reed

"If you can't laugh at yourself, laugh at somebody else"

Message posted via AccessMonster.com
 
G

Guest

The Error event does not trap runtime errors. You will need to add an error
handler to the procedure where the offending code lives and do your same
logic there.
 
R

ragtopcaddy via AccessMonster.com

Thanks Klaatu,

I have 2 combo boxes and a text box on the subform. Would I place the code in
the after update event of all 3?

Bill
The Error event does not trap runtime errors. You will need to add an error
handler to the procedure where the offending code lives and do your same
logic there.
I am trying to replace the Access msg (with no runtime error # in the dialog
box):
[quoted text clipped - 25 lines]

--
Bill Reed

"If you can't laugh at yourself, laugh at somebody else"

Message posted via AccessMonster.com
 
G

Guest

In the subform's After Update event.

ragtopcaddy via AccessMonster.com said:
Thanks Klaatu,

I have 2 combo boxes and a text box on the subform. Would I place the code in
the after update event of all 3?

Bill
The Error event does not trap runtime errors. You will need to add an error
handler to the procedure where the offending code lives and do your same
logic there.
I am trying to replace the Access msg (with no runtime error # in the dialog
box):
[quoted text clipped - 25 lines]

--
Bill Reed

"If you can't laugh at yourself, laugh at somebody else"

Message posted via AccessMonster.com
 
D

Dirk Goldgar

ragtopcaddy via AccessMonster.com said:
I am trying to replace the Access msg (with no runtime error # in the
dialog box):

"The changes you requested to the table were not successful because
they would create duplicate values in the index, primary key, or
relationship. Change the data in the field or fields that contain
duplicate data, remove the index, or redefine the index to permit
duplicate entries and try again."

with my own using the following code:

Private Sub Form_Error(DataErr As Integer, Response As Integer)
If Err.Number = 3022 Then
Response = acDataErrContinue
MsgBox "You tried to enter a pair of indices that are already
represented in the recordset." & vbCrLf & _
"Please OK this msg box and hit the ""Esc"" key to clear
the error. " & vbCrLf & _
"You can then find and change the MR Level for the indices
or add 2 different indices.", _
vbOKOnly + vbCritical, "Duplicate Record"
End If
End Sub

If it was working, I wouldn't be posting, so what gives? Err.Number =
0 when the code runs, so nothing happens and the same old access msg
is displayed.

Thanks,

Bill

In the event procedure for the Error event, the DataErr argument gives
the number of the error. So instead of ...
If Err.Number = 3022 Then

write ...

If DataErr = 3022 Then
 
R

ragtopcaddy via AccessMonster.com

Dirk and Klaatu,

Thank you both for all of your help.
There will be an extra $5 in your respective pay envelopes ;-)

Bill R

Dirk said:
I am trying to replace the Access msg (with no runtime error # in the
dialog box):
[quoted text clipped - 27 lines]

In the event procedure for the Error event, the DataErr argument gives
the number of the error. So instead of ...
If Err.Number = 3022 Then

write ...

If DataErr = 3022 Then

--
Bill Reed

"If you can't laugh at yourself, laugh at somebody else"

Message posted via AccessMonster.com
 
D

Dirk Goldgar

ragtopcaddy via AccessMonster.com said:
Dirk and Klaatu,

Thank you both for all of your help.
There will be an extra $5 in your respective pay envelopes ;-)

Oh, boy! Thanks, Bill!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top