R
Ryan
I have a form in Access 97 and on its BeforeUpdate event I placed code
that scans all the controls on the form and, if the field is required,
will stop the update from occurring and provide a nice message to the
user:
Dim ctrl As Variant
For Each ctrl In Me.Controls
If InStr(1, ctrl.Tag, "Required") Then
If IsNull(ctrl.Value) Then
msgbox "You cannot leave...Please fill in...and
try...again."
ctrl.Setfocus
Cancel = True
Exit Sub
End If
End If
Next ctrl
The code works great the first time I go to commit a change with a
field left blank. It also works great if I keep trying to save my
change without doing anything. If, however, I change anything in the
field and try to save again, the BeforeUpdate event no longer fires
and Access Default Error message takes over. Also, the same thing
happens if I am just editing a record. If I delete the contents of a
field and go to save, the BeforeUpdate does not fire, and I am again
faced with Access's built in error message. Is there any way around
this? (I have also tried the above code without ctrl.SetFocus.
that scans all the controls on the form and, if the field is required,
will stop the update from occurring and provide a nice message to the
user:
Dim ctrl As Variant
For Each ctrl In Me.Controls
If InStr(1, ctrl.Tag, "Required") Then
If IsNull(ctrl.Value) Then
msgbox "You cannot leave...Please fill in...and
try...again."
ctrl.Setfocus
Cancel = True
Exit Sub
End If
End If
Next ctrl
The code works great the first time I go to commit a change with a
field left blank. It also works great if I keep trying to save my
change without doing anything. If, however, I change anything in the
field and try to save again, the BeforeUpdate event no longer fires
and Access Default Error message takes over. Also, the same thing
happens if I am just editing a record. If I delete the contents of a
field and go to save, the BeforeUpdate does not fire, and I am again
faced with Access's built in error message. Is there any way around
this? (I have also tried the above code without ctrl.SetFocus.