For Each Next Loop

  • Thread starter Thread starter Emma Hope
  • Start date Start date
E

Emma Hope

Hi All,

I want to do the following:

For Each Field In [Forms]![frmIncome]
If Field.IsVisible Then
Field.Required = True
Else
Field.Required = False
End If
Next

I know that 'Field' isn't right but i don't know how to structure this code
to look at each field on my form, please can anyone help?

Thanks
Emma
 
Emma,

Try something like this:

Sub test()
Dim ctl As Control

For Each ctl In Me
If TypeOf ctl Is TextBox Then
ctl.required = False
Else
ctl.required = True
End If
Next
End Sub

this is just a dummy sub procedure so place the code in your procedure. The
me word refers to the active form but if you would like to you can use the
full name as well.

Don't know if this is going to work though because you will be testing
runtime so you have to figure out the exact event to trigger this.

hth
 
You cannot set a Required property for a field or control in a form.

You need to give us a lot more specific details about what you mean by
"required" and in what context. And at what point in the form's operation /
use should such conditions be set up on the form.
 
Back
Top