Hiding Items on form

R

ravindar thati

i have some items like text boxes, buttons, list boxes, etc on a form.
my requirement is when the form loads, only one button should be
displayed. if and only if i click that button, the remaining items
should be displayed.

one possibility is write code in form load such that initially the
items will be hidden, and button event makes them visible.
but i have many items on this form any they may increase from time to
time. i dont want to write for each items that they have to hide at
form loading and visible on button click.
is there any easy way such that we can hide all the items on a form
except a button like this?
 
G

Guest

Hi Ravindar,

One way you can accomplish this is to use thet 'tag' property. Each control
has a 'tag' property. You can put a value in the tag property for each
control you want to treat as a group. For example, for each control you want
to hide, put "Green" in the tag property of that control (it doesn't matter
what you use, just as long as you are consistent....all controls you want to
manipulate as a group have the same value ("Green" in my example)). It's
probably better form to use something more descriptive than 'Green',
though....

Then, run a For Each loop whenever you want to manipulate the group of
controls:

__________________
Sub SomeButton_Click()
Dim ctl as Control

For Each ctl in Me
If Me.ctl.tag = "Green" Then
Me.ctl.visible = True
End If
Next ctl

End Sub
______________

In the on_current event of the form, you could have:
____________
Sub Form_Current()
Dim ctl as Control

For Each ctl in Me
If Me.ctl.tag = "Green"
Me.ctl.visible = False
End If
Next ctl

End Sub
__________

The two code blocks above hide the controls with the 'Green' tag whenever
you move to a new record, and then make them visible when you click the
button (Somebutton).

If you do it that way, then when you add a new control that you want to be
treated as the "Green" controls, just make sure you give it the tag value
"Green".

Hope that helps,
CW
 

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