Check fields before saving form

  • Thread starter Thread starter Froto
  • Start date Start date
F

Froto

I have a form which has 8 fields that need to be filled
before the form is saved. What I would like is for code
to check that once a user selects the save record button
the form would be checked that the 8 fields have been
filled out,and if not a msgbox would popup for each field
thats blank and let the user know which ones need to be
filled out. Help much appreciated
 
I have a form which has 8 fields that need to be filled
before the form is saved. What I would like is for code
to check that once a user selects the save record button
the form would be checked that the 8 fields have been
filled out,and if not a msgbox would popup for each field
thats blank and let the user know which ones need to be
filled out. Help much appreciated

On way is to tag all of the controls that need to have an entry in.
For instance if you selected all 8 of the controls and placed
"Required" in the Tag property then the following would do what you
wanted:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim ctl As Control

For Each ctl In Me.Controls
If ctl.Tag = "Required" Then
If Len(ctl & "") = 0 Then
MsgBox "Please make an entry."
ctl.SetFocus
Cancel = True
Exit For
End If
End If
Next

End Sub

- Jim
 
Back
Top