0

I currently have a an after update event that cycles through the textboxes in a form and toggles their visibility on if they are numbered below a certain threshold number.

Dim i As Long Dim iMin As Long Dim iMax As Long iMin = 1 iMax = Me.txtMeasure.Value With Me For i = iMin To iMax .Controls("V" & i).Visible = True Next i End With 

The textboxes are named V1, V2, V3...V110, etc." while the labels corresponding to each textbox are labeled lblV1, lblV2, lblV3, lblV110, etc." The textboxes and labels are defaulted to be invisible while the after update event toggles their visibility on. The code works for the textboxes but fails to work for the labels. I have noticed that the while the labels don't appear visible, switching to design view and then back to form view, the labels suddenly appear visible. Is there a way to debug this so that they both appear visible at the same time?

3
  • where is the code which set labels visible? Commented Jul 25, 2016 at 1:12
  • I am new to access, this code was provided to me via another stackflow user. I thought that since the textboxes and the labels are named V1 and lblV1, then the code would adjust both. stackoverflow.com/questions/38510238/… Commented Jul 25, 2016 at 12:25
  • If the labels are attached to their textboxes, they should automatically be set visible/invisible with their parent textboxes. Commented Jul 25, 2016 at 12:50

2 Answers 2

0

Try this , it loops through controls and if it is a textbox or label you can do what you want with them, I have set them to Visible in this code.

Dim con As Control Dim i As Long Dim iMin As Long Dim iMax As Long Dim textBoxArr Dim j As Long iMin = 1 iMax = Me.txtMeasure.Value textBoxArr = Array("V1", "V2", "V3", "V4", "V5", "V6", "V7") For Each con In Me.Controls If TypeName(con) = "TextBox" Or TypeName(con) = "Label" Then For j = 0 To UBound(textBoxArr) If con.Name = textBoxArr(j) Or con.Name = "lbl" & textBoxArr(j) Then con.Visible = True: Exit For End If Next j End If Next con 
Sign up to request clarification or add additional context in comments.

3 Comments

This makes visible all 110 textboxes and labels. I need to only make visible as many textboxes as "Me.txtMeasure.Value" indicates (hence the original with loop).
I can't do that for you. You will need to test each control inside the if statement and filter out the ones you want visible etc. If you don't know how to do that ,get back to me.
OK, I updated the code to at least test for the textbox and the Label. You will have to adjust the code to suit the names of your controls.
0

You were able to add only one row to your code.

 Dim i As Long Dim iMin As Long Dim iMax As Long iMin = 1 iMax = Me.txtMeasure.Value With Me For i = iMin To iMax .Controls("V" & i).Visible = True .Controls("lbl" & i).Visible = True Next i End With 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.