ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Combo box controlling visibility (https://www.excelbanter.com/excel-programming/282003-combo-box-controlling-visibility.html)

chis

Combo box controlling visibility
 
I have a user form in VB that contains multiple
comboboxes. I am looking to haave the first combobox
control the Visible property of the other boxes. any
help is appreciated

Tom Ogilvy

Combo box controlling visibility
 
Private Sub combobox1_Click()
dim cbox = MSForms.Combobox
for each ctrl in Userform1.Controls
if typeof ctrl is MsForms.Combobox then
set cbox = ctrl
if right(cbox.name,1) < 1 then
cbox.visible = False
end if
end if
Next
Controls("Combobox" & combobox1.Listindex + 2).Visible = True
Me.Repaint
End Sub

would be a guess at what you want.

--
Regards,
Tom Ogilvy


chis wrote in message
...
I have a user form in VB that contains multiple
comboboxes. I am looking to haave the first combobox
control the Visible property of the other boxes. any
help is appreciated




Chris LeBlanc[_2_]

Combo box controlling visibility
 
Hello again. Ithink I might have been a little vague with what I was
looking for. I have combobox1 and it has a few variables. When the
user selects variable 1 I would like combobox2 to become visible. If
they choose variable 2 then combobox3 becomes visible and so on.
I don't knw why I didn't put it that way the first time.


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Tom Ogilvy

Combo box controlling visibility
 
That is what I assumed, that is what I gave you although I hide all but
combobox1 first and then the appropriate combobox is made visible. It
assumes comboboxes are named combobox1, combobox2, etc

so if the select item is the first item, then listindex is zero and zero
plus 2 is 2, so combobox & (listindex + 2) is made visible (combobox2).



--
Regards,
Tom Ogilvy

"Chris LeBlanc" wrote in message
...
Hello again. Ithink I might have been a little vague with what I was
looking for. I have combobox1 and it has a few variables. When the
user selects variable 1 I would like combobox2 to become visible. If
they choose variable 2 then combobox3 becomes visible and so on.
I don't knw why I didn't put it that way the first time.


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!




Chris

Combo box controlling visibility
 
Hi there again. I pasted the code into the form's codes and I receive
an error. The error is that "dim cbox = MSForms.ComboBox" is a compile
error:Syntax error.



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Tom Ogilvy

Combo box controlling visibility
 
dim cbox = MSForms.Combobox
should be
dim cbox as MSForms.Combobox

while I apologize for the typo, should you really be attempting this?

Anyway, I copied this form a working USERFORM

Private Sub combobox1_Click()
Dim cbox As MSForms.ComboBox
For Each ctrl In UserForm1.Controls
If TypeOf ctrl Is MSForms.ComboBox Then
Set cbox = ctrl
If Right(cbox.Name, 1) < 1 Then
cbox.Visible = False
End If
End If
Next
Controls("Combobox" & ComboBox1.ListIndex + 2).Visible = True
Me.Repaint
End Sub

Private Sub UserForm_Initialize()
Dim cbox As MSForms.ComboBox
For i = 1 To 5
For j = 1 To 4
Controls("ComboBox" & i).AddItem "Item " & j
Next
Next

For Each ctrl In UserForm1.Controls
If TypeOf ctrl Is MSForms.ComboBox Then
Set cbox = ctrl
If Right(cbox.Name, 1) < 1 Then
cbox.Visible = False
End If
End If
Next

End Sub

Tested in xl97, SR2

--
Regards,
Tom Ogilvy

Chris wrote in message
...
Hi there again. I pasted the code into the form's codes and I receive
an error. The error is that "dim cbox = MSForms.ComboBox" is a compile
error:Syntax error.



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!




Chris

Combo box controlling visibility
 
It is probably over my head but I have been trying to figure a quick way
to do what has taken an entire page of activex controls. Thanks for all
the help.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


All times are GMT +1. The time now is 05:20 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com