Using For....Next with Form Controls

S

Suggy1982

I have got 3 label controls on a form; each label control has it own name
(list below)
- lbl_div_nbr_1
- lbl_div_name_1
- lbl_div_charge_1

These set of 3 labels are then repeats 3 times on the same form, with the
name being the only thing that changes e.g.
- lbl_div_nbr_2
- lbl_div_name_2
- lbl_div_charge_2
- lbl_div_nbr_3
- lbl_div_name_3
- lbl_div_charge_3

I would like to use a For….next statement to look through and set the values
on these labels and make them visible, rather than having to write out 9
separate statements to do this, but my code below isn’t working. It is
returning an error saying it cannot find “Forms!menu!lbl_div_nbr_x.Captionâ€

For x = 1 to 3
Forms!menu!lbl_div_nbr_x.Caption = “testâ€
Forms!menu!lbl_div_nbr_x.Visible = True

Forms!menu!lbl_div_name_x.Caption = “testâ€
Forms!menu!lbl_div_name_x.Visible = True

Forms!menu!lbl_div_charge_x.Caption = “testâ€
Forms!menu!lbl_div_charge_x.Visible = True
Next
 
D

Dirk Goldgar

Answered in microsoft.public.access.modulesdaovba, where you posted this
question independently. That's called "multiposting", and it's generally
frowned on because others don't know what answers have already been given,
and so they duplicate the effort. Also it's harder for you to keep track of
the various replies, and it's harder for later readers of the question, who
may be looking for the same answer, to learn what they need.

In most cases a single, well-chosen newsgroup will do. If your question
really is relevant to more than one newsgroup, the approved technique is to
"crosspost" it instead, by listing multiple newsgroups in the To: or
Newsgroups: line of a single message. If you do that, the message and any
replies will appear in all the listed newsgroups automatically, which is
beneficial to all concerned.
 
D

De Jager

Suggy1982 said:
I have got 3 label controls on a form; each label control has it own name
(list below)
- lbl_div_nbr_1
- lbl_div_name_1
- lbl_div_charge_1

These set of 3 labels are then repeats 3 times on the same form, with the
name being the only thing that changes e.g.
- lbl_div_nbr_2
- lbl_div_name_2
- lbl_div_charge_2
- lbl_div_nbr_3
- lbl_div_name_3
- lbl_div_charge_3

I would like to use a For….next statement to look through and set the
values
on these labels and make them visible, rather than having to write out 9
separate statements to do this, but my code below isn’t working. It is
returning an error saying it cannot find
“Forms!menu!lbl_div_nbr_x.Captionâ€

For x = 1 to 3
Forms!menu!lbl_div_nbr_x.Caption = “testâ€
Forms!menu!lbl_div_nbr_x.Visible = True

Forms!menu!lbl_div_name_x.Caption = “testâ€
Forms!menu!lbl_div_name_x.Visible = True

Forms!menu!lbl_div_charge_x.Caption = “testâ€
Forms!menu!lbl_div_charge_x.Visible = True
Next
 

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

Similar Threads


Top