0

I'm trying to index through multiple textboxes in a form to change the Visible Property through an after Update event. The event occurs after a combo box designates a number of textboxes to cycle through. All the textboxes are named "V1, V2, V3...V110, etc.) I'm relatively new to VBA and Access, how would I go about coding this?

0

1 Answer 1

3

you can use the following sub

 Option Explicit Sub ChangeTextBoxVisibility(iMin As Long, iMax As Long, visibilityState As Boolean) Dim i As Long With Me For i = iMin To iMax .Controls("V" & i).Visible = visibilityState Next i End With End Sub 

to be called as

ChangeTextBoxVisibility 3, 90, False'<--| set not visible all textboxes from "V3" to "V90" 
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks! This worked out great! Is there any way to also toggle the visibility of the labels associated with them? They're named in the same manner, so I'm hoping there should be a way to similarly toggle the visibility
you are welcome. If I fulfilled your original question then please mark answer as accepted. thank you. As for your new request use the same code changing the letter(s) only: if labels are named "L1", "L2", and so on then use .Controls("L" & i).Visible = visibilityState.
The labels are called "lblV1, lblV2, etc." so I don't see why I would need a new line of code. If I'm not mistaken, it should be visible and not visible just like the textboxes upon the update event, but it is not. However, when I switch to design view and then back into form view, the correct labels are visible/invisible along with the textboxes. Is this a bug that can be fixed? I feel like it just may be a matter of refreshing or something like that
Now I understand. It's a new question: post it as such
I've linked the new question at the following url stackoverflow.com/questions/38556025/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.