Hide/Show controls & labels

  • Thread starter Thread starter Walter
  • Start date Start date
W

Walter

This another question related to a previous post by RickB
earlier. How do you include the control's label in the
hide/show process indicated? I understand how to use the
Tag property and "If ctl.tag = "TagName" to indentify
specific controls since I don't need to include all of
the form's contorls in this process. Since I need to set
the Enabled Property, if I include the labels in the Tag,
I get an error because Enable is not a label Property.

form's OnCurrent Event
Dim C As Control
For Each C In Me.Controls
If C.Tag = "Option" Then
C.Visible = False
C.Enabled = False
Next

Also, if a control contains data, i.e. was activated by
criteria in another control thereby allowing data entry,
how do you include this to make this control and it's
label visible when you return to this record?

I appreciate your help,
Walter
 
Walter,
If a control is Not Visible, it is... for all practical purposes...
Disabled.
An Invisible field can't be entered or updated, and won't generate any
events...
which is the same as Disabled and Locked.

If you must Disable though, you'll probably need to use a different Tag
for Labels, and another for Text, and run two loops... one for Labels with
no disable and one for Text with it.

hth
Al Camp
 
This another question related to a previous post by RickB
earlier. How do you include the control's label in the
hide/show process indicated? I understand how to use the
Tag property and "If ctl.tag = "TagName" to indentify
specific controls since I don't need to include all of
the form's contorls in this process. Since I need to set
the Enabled Property, if I include the labels in the Tag,
I get an error because Enable is not a label Property.

form's OnCurrent Event
Dim C As Control
For Each C In Me.Controls
If C.Tag = "Option" Then
C.Visible = False
C.Enabled = False
Next

Also, if a control contains data, i.e. was activated by
criteria in another control thereby allowing data entry,
how do you include this to make this control and it's
label visible when you return to this record?

a hidden (not visible) control doesn't need to be disabled, if you
don't see it you can't touch it.

BTW: are the labels "attached" to the controls? if yes the it's enough
to hide the controls, the labels are following the control

if they are not attached then go to the label---press ctrl-X--chose
the masterControl and press ctrl-V then it's attached
 
-----Original Message-----
Thanks for the help. In the reply from Andi, he stated
that attached labels followed the controls. I left off
the enabled property and it worked. However, when I added
criteria for cells with data, the labels remain visible.
I've tried to create another loop by substituting L for C
and renaming the tags but I keep getting error messages.
Following is the code I have:

Dim C As Control
For Each C In Me.Controls
If IsNull(C) Then
If C.Tag = "Option" Then
C.Visible = False
Else
C.Visible = True
End If
Else
C.Visible = True
End If
Next

I can define L as Label but can't use labels in the for
each statement. If you can provide some insight as how to
create another loop or some other solution I would greatly
appreciate it. Also, since one of the controls is
formatted for currency, the IsNull doesn't work with it.
How do I specify IsNull or "0"?

Thanks again,
Walter
 
Thanks for the help. In the reply from Andi, he stated
that attached labels followed the controls. I left off
the enabled property and it worked. However, when I added
criteria for cells with data, the labels remain visible.
I've tried to create another loop by substituting L for C
and renaming the tags but I keep getting error messages.
Following is the code I have:

Dim C As Control
For Each C In Me.Controls
If IsNull(C) Then
If C.Tag = "Option" Then
C.Visible = False
Else
C.Visible = True
End If
Else
C.Visible = True
End If
Next
I use a different approch to such a problem:

a name the Label exact as the control with a pre "lbl"

so txtControl1 has a Label lblControl1

then you can do:

Dim C As Control
For Each C In Me.Controls
' All Control (the txt) which I want to hide have a special Tag
' here all with isnull and =0 and ="" will be hidden
if C.tag= "Hide" Then
If nz(C,0) =0 or nZ(C,"")="" then
me.controls("lbl" &mid(C.name,4)).visible=false
endif
endif
Next C

it might not be exactly what you want but it will give you the right
direction
 
Thanks, Andi. Gonna give it a shot.
Walter
-----Original Message-----

I use a different approch to such a problem:

a name the Label exact as the control with a pre "lbl"

so txtControl1 has a Label lblControl1

then you can do:

Dim C As Control
For Each C In Me.Controls
' All Control (the txt) which I want to hide have a special Tag
' here all with isnull and =0 and ="" will be hidden
if C.tag= "Hide" Then
If nz(C,0) =0 or nZ(C,"")="" then
me.controls("lbl" &mid(C.name,4)).visible=false
endif
endif
Next C

it might not be exactly what you want but it will give you the right
direction
word "manfred" to the first 10 lines in the message
 
Yes, I agree with Andi... IF the labels are properly "attached" to the text
control.
However, you didn't respond to my point that if a control is made
"invisible", it does not need to be disabled at all.
I would think that would make all the "disabling" code unnecessary...
hth
Al Camp
 
Back
Top