visible property

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i have a large number of text boxes on a form that i only want to appear visible when certain parameters are met.
currently refering to each box and it's label individually is a very repetetive process:

if cboDoc = "Slip" Then
lbl1.Visible=True
txt1.Visible=True
lbl2.Visible=True
txt2.Visible=True... and so on.

is there a way to refer to the form items other than doing it like this?
 
wesley said:
i have a large number of text boxes on a form that i only want to appear visible when certain parameters are met.
currently refering to each box and it's label individually is a very repetetive process:

if cboDoc = "Slip" Then
lbl1.Visible=True
txt1.Visible=True
lbl2.Visible=True
txt2.Visible=True... and so on.

is there a way to refer to the form items other than doing it like this?
You can set the Tag property for all these controls to something
recognizable (e.g. "hide") and then execute this (from one handler or
the other in the same form):

sub ShowAll(bState as boolean)
dim ctl as control
for each ctl in me.controls
if ctl.tag="hide" then ctl.visible=bState
next
 
Assuming controls named txt1 through txt40:

Dim strName As String
Dim i As Integer
Dim bShow As Boolean

bShow = Nz(Me.cboDoc = "Slip", False)

For i = 1 to 40
strName = "txt" & i
Me(strName).Visible = bShow
Next


BTW, when you hide/show a text box, the attached label changes as well.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

wesley said:
i have a large number of text boxes on a form that i only want to appear
visible when certain parameters are met.
 
i have entered the following code

Dim strName As Strin
Dim i As Intege
Dim bShow As Boolea

bShow = Nz(Me.cboDoc = "Endorsement", False

For i = 21 To 2
strName = "txt" &
Nex

If cboDoc.Value = "Endorsement" And txtQC.Value > 0 The
Me(strName).Visible = bSho
txt21.SetFocu
Els
cmbAddTime.SetFocu
End I

this seems to be working but only txt25 becomes visible on the form?
 
Your For ... Next loop needs to be around the rest of the code.
As it is, the loop runs and does nothing.
 
wesley said:
i have entered the following code:

Dim strName As String
Dim i As Integer
Dim bShow As Boolean

bShow = Nz(Me.cboDoc = "Endorsement", False)

For i = 21 To 25
strName = "txt" & i
Next

If cboDoc.Value = "Endorsement" And txtQC.Value > 0 Then
Me(strName).Visible = bShow
txt21.SetFocus
Else
cmbAddTime.SetFocus
End If

this seems to be working but only txt25 becomes visible on the form?

Yes.

It all happens between For and Next. Whatever actions you wish to
perform on all combinations must be between those two. (move the Next
down a bit!)
 
Allen said:
Your For ... Next loop needs to be around the rest of the code.
As it is, the loop runs and does nothing.
Hur, sorry, saw the Reply after hitting Send.
 
Back
Top