Example

Validate New Records.


Validate New Records code snippet.

The following is a simple example of how to validate a new record and display a message box if the entry is invalid. The code snippet assumes you have a DGrid control named "DGrid1" sited on the form.


Private Sub DGrid1_BeforeAddNew(Cancel As Boolean, CancelMsg As String)
    Dim tmp As Variant
    tmp = ss.Cols(3).NewValue
    'Check the value in the fourth column
    'of the grid. If not between 1 and 4 display
    'a message box and cancel the add new record.
    If tmp < 1 Or tmp > 4 Then
        CancelMsg = "Enter a value between 1 and 4 in column 3!"
        Cancel = True
    End If
End Sub