Example
Validate User Edits.
Validate User Edits code snippet.
The following is a simple example of how to validate what a user has entered 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_BeforeEdit(ByVal Row As Long, ByVal Col As Long, _
OldVal As String, NewVal As String, Cancel As Boolean, CancelMsg As String)
'Check the value in the fourth column
'of the grid. If not between 1 and 4 display
'a message box and cancel the edit.
If Col = 3 Then
If Val(NewVal) < 1 Or Val(NewVal) > 4 Then
CancelMsg = "Enter a value between 1 and 4!"
Cancel = True
End If
End If
End Sub