PC Review


Reply
Thread Tools Rate Thread

Combo box controlling visibility

 
 
chis
Guest
Posts: n/a
 
      10th Nov 2003
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
 
Reply With Quote
 
 
 
 
Tom Ogilvy
Guest
Posts: n/a
 
      10th Nov 2003
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 <(E-Mail Removed)> wrote in message
news:042101c3a729$de640360$(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
 
Chris LeBlanc
Guest
Posts: n/a
 
      10th Nov 2003
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!
 
Reply With Quote
 
Tom Ogilvy
Guest
Posts: n/a
 
      10th Nov 2003
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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!



 
Reply With Quote
 
Chris
Guest
Posts: n/a
 
      11th Nov 2003
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!
 
Reply With Quote
 
Tom Ogilvy
Guest
Posts: n/a
 
      11th Nov 2003
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 <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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!



 
Reply With Quote
 
Chris
Guest
Posts: n/a
 
      14th Nov 2003
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!
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create Check box that controls visibility of a text box or combo b Huskybydezign Microsoft Access Forms 1 17th Jul 2009 12:43 AM
Problem with controlling visibility of linkbutton =?Utf-8?B?TWFubnkgQ2hvaGFu?= Microsoft ASP .NET 6 5th Apr 2005 07:00 PM
Controlling Combo Box contents by another Combo Box Greg McLandsborough Microsoft Access Forms 1 1st Feb 2005 01:51 AM
controlling application visibility (also, terminology questions) =?Utf-8?B?UmljaA==?= Microsoft Dot NET Compact Framework 5 6th Nov 2004 05:34 AM
Controlling visibility and text value of a control jason Microsoft Access 0 22nd Jul 2003 04:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:51 PM.