showing fields

  • Thread starter Thread starter Lodewijk Olthof
  • Start date Start date
L

Lodewijk Olthof

I have a form with 9 optional fields and a form with names for these
optional fields (or no name).
When the form is opend, I want to check if each optional fields has a name
in the constant field. If so, the optional field is shown with that name.

I use the following syntax for it:
If Len([Forms]![frmConstanten]![stfVeld1]) > 0 Then
Me!BijschriftstfVeld1.Visible = True
Me!stfVeld1.Visible = True
Me!BijschriftstfVeld1.Caption = [Forms]![frmConstanten]![stfVeld1]
End If

This code is put 9 times in sub Form_Open. I was wondering if this can also
be done with a
For teller = 1 to 9
some code
Next teller

I hoped the code would be the same, but with 1 (etc.) changed to teller, but
that wil not work. Has anyone got a sugestion?
 
If you have a form with controls ctl1, ctl2, ....ctl9 then you can loop
through them by doing this....

dim i as integer
for i = 1 to 9
msgbox (me.controls("ctl" + cstr(i))) 'or whatever you want to do
next
 
Rob Oldfield said:
If you have a form with controls ctl1, ctl2, ....ctl9 then you can loop
through them by doing this....

dim i as integer
for i = 1 to 9
msgbox (me.controls("ctl" + cstr(i))) 'or whatever you want to do
next

Thanks, it works. Only when ctl2 equal null, I get an error message. What
about that?
When ctl2 is null, it means that the field should not be shown on my first
form.
 
Hi,
Use the IsNull function to get the behavior you want.
Help will show the syntax.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top