|
|
Title | Use the DBGrid control's BeforeUpdate event |
Keywords | DBGrid, BeforeUpdate, validation |
Categories | Controls, Database |
|
|
Use the DBGrid's BeforeUpdate event to validate changes before they are accepted.
If you cancel a change, watch for the event canceled error in the Error event handler and ignore it so the user does not see a system generated message box.
|
|
' Make sure that the EmployeeId field is
' a valid long integer.
Private Sub DBGrid1_BeforeUpdate(Cancel As Integer)
Dim test_value As Long
If DBGrid1.Col = 2 Then
On Error GoTo NotNumeric
test_value = CInt(DBGrid1.Text)
On Error GoTo 0
End If
' It's Ok. Leave Cancel alone (false).
Exit Sub
NotNumeric:
' Invalid value. Cancel the update.
Cancel = True
' Display an error message.
MsgBox "EmployeeId must be an integer."
End Sub
' Ignore canceled update errors.
Private Sub DBGrid1_Error(ByVal DataError As Integer, _
Response As Integer)
If DataError = 16389 Then Response = vbDataErrContinue
End Sub
|
|
|
|
|
|