-
make textboxes visible at runtime?
Hi there
I'm new to VBA and was wondering how I would go about doing this.
Basicaly I have 9 sets of text boxes on my userform and only wanted 1 set to appear unless the user enters 2 in the textbox (number of guests) therefore 2 sets of text boxes would appear and so on.
Any help would be much appreciated
Thanks
Mark
-
Hi,
Assuming you stick with the Standardnames of the Textboxes (TextBoxN) and they are numbered 1..10, then try this code for TextBox1:
[VBA]Private Sub TextBox1_Change()
Dim iX As Integer
If Val(TextBox1) < 11 And Val(TextBox1) > 1 Then
For iX = 2 To 10
Me.Controls("TextBox" & iX).Visible = (iX <= Val(TextBox1))
Next iX
End If
End Sub[/VBA]
GreetZ Hansueli
-
Hi Hansueli
thanks for the reply, so which part of the code do I change for the "number of guests" text box?
Thanks
Mark
-
Here is a screen sho to give a clearer picture
Thanks
Mark
-
Hi Mark,
OK, It looks you have a lot of controls.
If your NrOfGuest Textbox is named TextBox6 and your Guest(1) TextBox is named TextBox7 and the next TextBox8 aso, then modify the Code below as follows:
[vba]Private Sub TextBox6_Change()
Dim iX As Integer
If Val(TextBox6) < 11 And Val(TextBox6) > 1 Then
For iX = 2 To 10
Me.Controls("TextBox" & (5 + iX)).Visible = (iX <= Val(TextBox6))
Next iX
End If
End Sub[/vba]
GreetZ Hansueli
Last edited by Plagööri; 10-11-2009 at 09:07 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules