Check that certain fields are filled in

  • Thread starter Thread starter netadmin
  • Start date Start date
N

netadmin

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
 
If you need them filled with data from a table or query
you should set the RecordSource property to the table or
query you want to use, then set the ControlSource
property of each text box to the proper column within the
table or query. When a user updates the text box on the
form, the underlying table will be updated as well.
Please let me know if I am missing something.
 
The best way is to be sure that each field in the
underlying table has its Required property set to YES.

Another way is to use the Validation Rule for each
field/control to make sure data has been entered.

A last way would be to check all of the fields in sequence
for data before the record is saved, or the user moves to
another record.
 
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).
 
Back
Top