Basic code condense question

G

Guest

Is thier a better way to condense this code then to have read the same way
over and over each time? I have 5 sets of these and each field is set to be
visible if the option box has a check mark in it. I am only showing you one
full set for the "IsDisplayHistoricalGrowth" option box. If sthere is an
eaier way to do this could someone let me know. I am pretty new at this.

Below is fired via the optionbox IsDisplayHistoricalGrowth
Me.[YearFromHistoricalGrowth].Visible =
Nz(Me.[IsDisplayHistoricalGrowth], True)
Me.[YearToHistoricalGrowth].Visible =
Nz(Me.[IsDisplayHistoricalGrowth], True)
Me.[OneMileHistoricalGrowth].Visible =
Nz(Me.[IsDisplayHistoricalGrowth], True)
Me.[ThreeMileHistoricalGrowth].Visible =
Nz(Me.[IsDisplayHistoricalGrowth], True)
Me.[FiveMileHistoricalGrowth].Visible =
Nz(Me.[IsDisplayHistoricalGrowth], True)
 
G

Guest

Try:

Dim flg as Boolean
flg = Nz(Me.[IsDisplayHistoricalGrowth], True)
With Me
.[YearFromHistoricalGrowth].Visible = flg
.[YearToHistoricalGrowth].Visible = flg
.[OneMileHistoricalGrowth].Visible = flg
.[ThreeMileHistoricalGrowth].Visible = flg
.[FiveMileHistoricalGrowth].Visible = flg
End With
 
A

Alex Dybenko

Hi,
you can, for example set a Tag property for each set of textboxes, and loop
through all controls of a form, and depending on selected checkmark and tag
of each textbox - set Visible property
you can also try to use control's name, if they are similar like
"*HistoricalGrowth"

--
Best regards,
___________
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com
 

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

Top