On Error Goto....

G

Guest

Hi,

Can u pls.anybody solve this problem....?

i have set primary key for one fields, which indicates duplicate message
when i enter duplicate value. The message access display is too lengthy like
as below.

"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."

I wanted to display as my desire message, for which i used the following
code which is not working...

Private Sub Text18_AfterUpdate()

On Error GoTo Err_Text18_Click
Screen.PreviousControl.SetFocus
DoCmd.FindNext

Exit_Text18_Click:
Exit Sub

Err_Text18_Click:
If InStr(UCase(Err.Description), "DUPLICATE") > 0 Then
MsgBox "Eh..!..Its Duplicate value.."
text18.text = ""
Resume Next
End If

End Sub

Thnx..in advance..

Solar..
 
M

missinglinq via AccessMonster.com

These types of errors need to be trapped at the form level:

Private Sub Form_Error(DataErr As Integer, Response As Integer)
If DataErr = 3022 Then 'Attempt was made to duplicate Primary Key
MsgBox "Your Custom Message Goes Here", vbExclamation, "Duplicate
Primary Key Error"
Response = acDataErrContinue
End If
End Sub

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 

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