Basic code condense question

  • Thread starter Thread starter Guest
  • Start date Start date
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)
 
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
 
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
 
Back
Top