I have a form on which there are 10 fields which need to
be filled in, I would like to know what code I would use
to accomplish this and where I should place it.
Thank you
A couple of ways to do this:
- In table design mode make each of these fields Required. This is
probably a good idea, but the error message if you leave one blank can
be confusing to users.
- In the Form's BeforeUpdate event check each field; if it's blank
warn the user and Cancel the update. E.g.
Private Sub Form_BeforeUpdate(Cancel as Integer)
If Me!txtX & "" = "" Then
MsgBox "This field cannot be left blank!", vbOKOnly
Me!txtX.SetFocus
Cancel = True
End If
<etc>
If you want to get fancy you can loop through the controls - the
problem with this is that you need to distinguish those controls which
must be filled in from those which needn't (perhaps using the
control's Tag property).