Check for empty controls

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a database for making and implementing recommendations. It has
sections for the initial recommendation, the response, the follow-up, and the
final approval. Each of these sections has four to six fields. My initial
version of this database uses a single table. The data entry form is
separated into four tabs.
When somebody makes a recommendation they must fill in all of the fields on
the Recommendation tab. If they do not, they need to be reminded before
attempting to e-mail (SendObject), print, or exit from the record. I could
do this with an event at the e-mail command button, etc., but the only way I
can figure out is to test each field individually. I would like to test a
group of controls, and if any of them are null to generate a generic error
message ("All fields must be filled in", or something like that), then set
focus to a control that needs a value. If there are two or more empty
controls I suppose it would have to check each control in turn and set the
focus to the first empty one. If the user declines to fill in the fields,
the record will not be saved (or if they are on the second section, the data
they just entered will not be saved, but the data entered previously in the
first section will remain).
Or maybe there is a standard procedure for this situation that could work
more effectively than what I have outlined, in which case I would be glad to
learn of it. I tried searching for a previous posting on this topic, but
could not find a way to phrase the question that produced the desired search
results.
 
hi,
here is code i use in one of my forms to qualify input.
If IsNull(Me!txtControlNbr) Then
MsgBox (" Enter a Control Number.")
Exit Sub
Else
If IsNull(Me!txtVendor) Or IsNull(Me!txtBuyer) Then
MsgBox ("Not enough data to add as Record")
Exit Sub

Else
If IsNull(Me!txtVendor) Then
Me!txtVendorName.SetFocus
Exit Sub
Else
If IsNull(Me!txtBuyer) Then
Me!txtBuyer.SetFocus
Exit Sub
End If
End If
End If
End If
this is attached to a button that accepts the record.
if required fields are not filled in then the rest of the
code don't run because any null field cause the exit sub.
 
Thanks. I was stumbling in that general direction, but your code is tidier
and more compact than anything I have come up with so far.
 
Back
Top