visible property

W

wesley

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?
 
B

Bas Cost Budde

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
 
A

Allen Browne

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.
 
W

wesley

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?
 
A

Allen Browne

Your For ... Next loop needs to be around the rest of the code.
As it is, the loop runs and does nothing.
 
B

Bas Cost Budde

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!)
 
B

Bas Cost Budde

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.
 

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