Error Message Customization

Custom Error Message on Adding Record

This customization shows how to validate a record and set custom error message when adding a record with duplicate primary key.
Record Control Class
Select the record control class where this customization will be added
Table Name
Select a table to add new record
Primary Key
Select the primary key in the table
Primary Key Control
Select the primary key control
Applies to
RecordControl class
''' Override Validate method. If record exists, do not add the record and throw
''' custom error message to the user.
''' When an exception is thrown in the Validate() sub, it is caught in the SaveButton_Click handler.
''' SaveButton_Click handler calls RegisterJScriptAlert to report the error message to the user.
''' Throwing an exception ensures that the record will not be saved. If the exception is
''' not thrown the record is saved.
Public Overrides Sub Validate()

    ' Create a whereStr 
    Dim whereStr As String = ${${Table Name}ClassName}.${Primary Key}.InternalName & "='" & Me.${Primary Key Control}.Text & "'"
    Dim rec As ${${Table Name}RecordClassName} = Nothing
    ' Check if the record exists
    rec = ${${Table Name}ClassName}.GetRecord(whereStr)
    ' If record exists then throw custom error message to the user
    If (Not IsNothing(rec)) Then
       ' Set custom error message
        Throw New Exception("Record with this primary key already exists.")        
    End If
End Sub


Terms of Service Privacy Statement