hiding multiple items on form

S

stickandrock

I have a form that mutiple combo boxes and option boxes on it.....

Towards the top of the form I have option box group selection.

based on the selection I want to hide several items on the form and
consequently when the other selection is choosen I want to hide or unhide
other items.

Without having to name all the items I want to hide or unhide is there a
way to group those items to consolidate my vb logic into 1 hide or unhide
command

any and all input would be greatly appreciated....
 
D

Dirk Goldgar

stickandrock said:
I have a form that mutiple combo boxes and option boxes on it.....

Towards the top of the form I have option box group selection.

based on the selection I want to hide several items on the form and
consequently when the other selection is choosen I want to hide or unhide
other items.

Without having to name all the items I want to hide or unhide is there a
way to group those items to consolidate my vb logic into 1 hide or unhide
command

any and all input would be greatly appreciated....


I assume you're talking about hiding controls, not records. What I have
always done -- assuming that there's nothing inherent in the controls that
makes the groups discernible -- is to use the controls' Tag properties to
identify what groups they belong to. So I might set the Tag properties of
one set of controls to "A", and another set of controls to "B". Then I
could have a procedure like this to loop through all the controls with a
given Tag property value and set the Visible property:

'----- start of air code -----
Private Sub SetControlsVisible(pTag As String, pVisible As Boolean)

Dim ctl As Access.Control

For Each ctl In Me.Controls

If ctl.Tag = pTag Then
ctl.Visible = pVisible
End If

Next ctl

End Sub
'----- end of air code -----

With that procedure in the form's module, I could hide all the controls
tagged "A" like this:

SetControlsVisible "A", False

.... and show all the controls tagged "B" like this:

SetControlsVisible "B", True

Note that you can't hide the control that has the focus, so you should only
call that simplistic procedure to hide controls when you know none of the
controls in the group in question has the focus. Otherwise, an error will
be raised. A more comprehensive solution would have to include code to
handle that problem.
 

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