Well, you cannot override the exception since the error is actually happening on the SQL Server itself and you will never be able to work around the constraint. We generally test for the uniquness of a value using a scalar command within the CheckRulesOnCurrentRow event.Public Function CheckForDuplicate(ByVal MyPassedTestValue As String) As Integer
Dim loCommand As New SQLCOmmand()
Dim lnPK As Integer
'-- Skip the current record
IF Me.Count > 0 Then
lnPK = Me.PrimaryKeyField
Else
lnPK = -1
End If
'-- Build the command text
loCommand.CommandText = "SELECT COUNT(*) FROM MyTable WHERE MyPrimaryKeyField != @MyPrimaryKeyField And MyTestField = @MyTestField"
'-- Create the parms
loCommand.Parameters.Add("@MyPrimaryKeyField",SqlDataType.Int)
loCommand.Parameters.Add("@MyTestField",SqlDataType.VarChar)
'-- Set the parms
loCommand.Parameters("@MyPrimaryKeyField").Value = lnPK
loCommand.Parameters("@MyTestField").Value = MyPassedTestValue
'-- Return the results
Return CType(Me.ExecuteScalar(loCommand), Integer)
End Sub