Need help w/ Form Error Function

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

I have a tables that uses 2 indexed fields. If the user would create a
duplicate
entry then the customized message box below (***s) appears and the selected
value
cannot be entered.

However, as of now, I either have to select a new value (from a list) or
backspace
the entered value and then delete the blank row. Either way this is not
what I want.

Does anyone know how to customize the function below so that it
automatically deletes the duplicate value that was attempted to be added to
the record set (after having clicked OK on the message box)?


**************
Private Sub Form_Error(DataErr As Integer, Response As Integer)

If DataErr = 3022 Then
MsgBox "This value already exists for the selected entity - please
enter unique value!"
Response = acDataErrContinue

End If
End Sub
**************


Thanks,
Mike
 
Hello Mike
First of all, create a public variable "ControlID" as a
string.
Next for each controls "On Got Focus" assign a value to
ControlID, e.g. Field1 for the first field, Field2 for the
second field.
Now add this code: -
Private Sub Form_Error(DataErr As Integer, Response As
Integer)
If DataErr = 3022 Then
MsgBox ("Duplicate Data Error")
If ControlID="Field1" then Me.Field1.SetFocus
If ControlID="Field2" then Me.Field2.SetFocus
Exit Sub
End If
MsgBox (Err.Number & ", " & Err.Description)
End Sub

HTH



Tony C.
 
Back
Top