I'm having trouble looping through text boxes (with various names) on
a form.
Since you are likely to have other controls on the form, a little bit of
judicious naming can make them look like a control array:
' assuming the text boxes are called txtRequired01, txtRequired02, etc
for i = 1 to 21
strControlName = format(i, """txtRequired"00")
if isnull(me.controls(strControlName).Value) Then
' it's empty
' warn the user
msgBox "You forgot box number " & i
' and put the focus back there
me.controls(strControlName).SetFocus
' set the flag
fErrorFound = True
' and don't do any more checking
exit for
end if
next i
If fErrorFound = False
' validation okay, carry on...
If the names are not regular, you can still do it like this:
' control the names: you could get these from a table
' if they have to be very dynamic
a_varTextBoxes = Array("txtFName", "txtLName", "etc")
' and iterate them
for i = 0 to UBound(a_varTextboxes)
If IsNull(me.controls(a_varTextBoxes(i)).Value) Then
' etc etc
Hope that helps
Tim F