Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting visible properties using checkbox (lots of them)

Status
Not open for further replies.

millrat

Technical User
Dec 23, 2003
98
US
Hi all,

Can anyone help with a more elegant solution?

I have multiple checkboxes on a form. Each check box sets the visible property of a corresponding label. This works in the short term but as I add more check boxes (with more combinations) it will become unwieldy to code.

eg. (short version)

Sub lblVisible()

If Me.chkA = False And Me.chkB = False And Me.chkC = False Then
Me.lblA.Visible = False
Me.lblB.Visible = False
Me.lblC.Visible = False
ElseIf Me.chkA = True And Me.chkB = False And Me.chkC = False Then
Me.lblA.Visible = True
Me.lblB.Visible = False
Me.lblC.Visible = False
ElseIf Me.chkA = True And Me.chkB = True And Me.chkC = False Then
Me.lblA.Visible = True
Me.lblB.Visible = True
Me.lblC.Visible = False
ElseIf etc....for all the combinations

End Sub

This sub then goes in the checkbox AfterUpdate and FormCurrent Subs

Is this a case for Select Case??

Thanks in advance
millrat
 
It seems from the above that this should work:

[tt]Me.lblA.Visible = Me.chkA
Me.lblB.Visible = Me.chkB
Me.lblC.Visible = Me.chkC[/tt]
 
Remou,

I wish it were this easy. However, maybe I didn't make it clear enough at the start. chkA and lblA are just arbitary tags. e.g. For a situation where say. chkA = True and chkB = True...lblA is visible and lblB is not.... or if a different combination of check boxes are either true or false a diffent combination of labels are visible. As you can imagine after 4 or 5 controls the amount of combinations add up...

I guess I am hoping for a diffent approach than the If Then Else one...

Cheers,
millrat
 
In the example you gave, in every case where the If statement was false, the matching label was not visible and where the If statement was true, the label was visible. To break down:

Statement 1
If Me.chkA = False
Me.lblA.Visible = False
... And Me.chkB = False
Me.lblB.Visible = False
... And Me.chkC = False Then
Me.lblC.Visible = False

Statement 2
ElseIf Me.chkA = True
Me.lblA.Visible = True
... And Me.chkB = False
Me.lblB.Visible = False
... And Me.chkC = False Then
Me.lblC.Visible = False

Statement 3
ElseIf Me.chkA = True
Me.lblA.Visible = True
... And Me.chkB = True
Me.lblB.Visible = True
... And Me.chkC = False Then
Me.lblC.Visible = False
ElseIf etc....for all the combinations

Which resolves to:
Labela.Visible = Chka
as the only the possible values for Chka are True and False.

Now, in what way does the situation you have differ from the example you gave? And what are the actual label names?
 
Remou,

Sorry to have wasted your time but I have found the solution, Thanks for replying.

Cheers
millrat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top