Handling ODBC errors on bound form

  • Thread starter Thread starter Reid
  • Start date Start date
R

Reid

I have an Access 2000 form bound to a SQL 2000 table. When the user doesn't
supply all required information in the required fields (Not Null SQL
columns) and tries to commit, I get an ugly ODBC error that isn't trapped in
any form object's OnError event. I'd rather handle the error and display a
friendly message than analyze each control in the BeforeUpdate event. Any
ideas? Thanks.
 
Why don't you test all of the fields/controls in the Forms BeforeUpdate
event and set cancel to True and do a Message Box if the user is not
following your validation rules. Code might look like:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strErrMsg As String
If Len(Nz(txtSomeField1.Value, "")) = 0 Then
If Len(strErrMsg) = 0 Then txtSomeField1.SetFocus
strErrMsg = strErrMsg & "Must specify txtSomeField1!" & vbCrLf
End If
If Len(Nz(txtSomeField2.Value, "")) = 0 Then
If Len(strErrMsg) = 0 Then txtSomeField2.SetFocus
strErrMsg = strErrMsg & "Must specify txtSomeField2!" & vbCrLf
End If
If Len(strErrMsg) > 0 Then
Cancel = True
MsgBox strErrMsg, vbExclamation, "Validation Error"
End If
End Sub

Ron W
 
Back
Top