Faster way to hide/unhide

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

Guest

I have 30 labels (Called lblField..) & associated fields (Called txtField..),
is it possible to make bulk changes with setting each item. labels & Fields
1-8 are visible & the rest are not, 9-18 are visible & the rest are not &
19-30 are visible & the rest are not, currently I have 60 lines of code for
each instance.
 
If you group the controls in some custom routines, then you can go for the
first case:

me.set1 = true ' display 1-8
me.set2 = false ' hide 9-18
me.set3 = false ' hide 19-30


And, for code to just show 9-18, you can go:

me.set1 = false
me.set2 = true
me.set3 = false

The following code assumes that you go some type of "sequential" number
schemes for the controls on your screen. I am going to assume "text1" ,
"text2" etc, but it could as well be txtField


Public Property Let Set1(bolShow As Boolean)

Dim i As Integer ' loop counter
Dim strC As String ' contorl pointer

For i = 1 To 8
strC = "txtField" & i
Me(strC).Visible = bolShow
Next i

End Property

You can simply code the set2, and set3 as above....

So, put the above code in the form...note how even when you type in me.set1
that inteli-sense shows your choice as true false....
 
I question a structure like this however....
If you name your controls like
lbl1
txt1
lbl2
txt2
....
lbl30
txt30
You can write code like:

Public Sub ShowCtls( intMin as Integer, intMax as Integer)
dim intCtl as Integer
For intCtl = 1 to 30
Me("lbl" & intCtl).visible = (intCtl>=intMin and intCtl<=intMax)
Me("txt" & intCtl).Visible = (intCtl>=intMin and intCtl<=intMax)
Next
End Sub

Call the procedure like
ShowCtls 1, 8
 
Back
Top