UserForm second combobox won't keep value with first choice.

ajsmith68502

New Member
Joined
Sep 20, 2016
Messages
9
Sorry if this has been asked before, but I can't find an answer. I have a userform with multiple comboboxes and the second one has to be chosen twice to keep it's value. Not sure why. The others are fine. Here's the code:

Private Sub UserForm_Initialize()
Application.EnableEvents = False


'Clear


UserForm1.cbFamily.Value = ""
UserForm1.cbNS1.Value = ""
UserForm1.cbNS1.Visible = False
UserForm1.cbNS2.Visible = False
UserForm1.lblNS1.Visible = False
UserForm1.lblNS2.Visible = False
'------------------------------------------Accessory list populates
With cbFamily
.AddItem "Cone"
.AddItem "Bellow"
.AddItem "Bellow with 90° Elbow"
.AddItem "Elbow"
.AddItem "Elbow - 90° Mitred"
.AddItem "Flex"
.AddItem "Flex with 90° Elbow"
.AddItem "Outlet Extension 45° Cut with Bird Screen"
.AddItem "Tube"
End With
Application.EnableEvents = True
End Sub


Private Sub cbFamily_Click()
Application.EnableEvents = False
'-----------------------------------------cbNS1 populates
Dim index As Integer
index = cbFamily.ListIndex


Select Case index
'----------------Cone NS1
Case Is = 0
With cbNS1
.AddItem "8"
.AddItem "10"
.AddItem "12"
.AddItem "14"
.AddItem "16"
.AddItem "18"
.AddItem "20"
.AddItem "22"
.AddItem "24"
.AddItem "26"
.AddItem "28"
.AddItem "30"
End With
'----------------Bellow NS1
Case Is = 1
With cbNS1
.AddItem "4"
.AddItem "5"
.AddItem "6"
.AddItem "8"
.AddItem "10"
.AddItem "12"
.AddItem "14"
.AddItem "16"
.AddItem "18"
.AddItem "20"
.AddItem "22"
.AddItem "24"
.AddItem "26"
.AddItem "28"
.AddItem "30"
End With
'----------------Bellow with 90° Elbow NS1
Case Is = 2
With cbNS1
.AddItem "5"
.AddItem "6"
.AddItem "8"
.AddItem "10"
.AddItem "12"
End With
'----------------Elbow NS1
Case Is = 3
With cbNS1
.AddItem "2.5"
.AddItem "3"
.AddItem "3.5"
.AddItem "4"
.AddItem "5"
.AddItem "6"
.AddItem "8"
.AddItem "10"
.AddItem "12"


End With
'----------------Elbow - 90° Mitred NS1
Case Is = 4
With cbNS1
.AddItem "10"
.AddItem "12"
.AddItem "14"
.AddItem "16"
.AddItem "18"
.AddItem "20"
.AddItem "22"
.AddItem "24"
.AddItem "26"
.AddItem "28"
.AddItem "30"
End With
'--------------------Flex NS1
Case Is = 5
With cbNS1
.AddItem "2.5"
.AddItem "3"
.AddItem "3.5"
.AddItem "4"
.AddItem "5"
.AddItem "6"
.AddItem "8"
.AddItem "10"
.AddItem "12"
End With
'--------------------Flex with 90° Elbow NS1
Case Is = 6
With cbNS1
.AddItem "5"
.AddItem "6"
.AddItem "8"
.AddItem "10"
.AddItem "12"
End With
'------------------------Outlet Extension 45° Cut with Bird Screen
Case Is = 7
With cbNS1
.AddItem "5"
.AddItem "6"
.AddItem "8"
.AddItem "10"
.AddItem "12"
.AddItem "14"
.AddItem "16"
.AddItem "18"
.AddItem "20"
.AddItem "22"
.AddItem "24"
.AddItem "26"
.AddItem "28"
.AddItem "30"
End With
'--------------------Tube NS1
Case Is = 7
With cbNS1
.AddItem "2"
.AddItem "2.5"
.AddItem "3"
.AddItem "3.5"
.AddItem "4"
.AddItem "5"
.AddItem "6"
.AddItem "8"
.AddItem "10"
.AddItem "12"
.AddItem "14"
.AddItem "16"
.AddItem "18"
.AddItem "20"
.AddItem "22"
.AddItem "24"
.AddItem "26"
.AddItem "28"
.AddItem "30"
End With

End Select

UserForm1.cbNS1.Visible = True
UserForm1.lblNS1.Visible = True
Application.EnableEvents = True


End Sub


Private Sub cbNS1_Click()
Application.EnableEvents = False


UserForm1.cbNS2.Visible = True
UserForm1.lblNS2.Visible = True


'------------------------------------------cbNS2 Populates
Dim index As Integer
index = cbNS1.ListIndex


Select Case index
'---------------
Case Is = 0
With cbNS2
.AddItem "8"
.AddItem "10"
.AddItem "12"
End With

Case Is = 1
With cbNS2
.AddItem "Test"
End With
Case Is = 2
With cbNS2
.AddItem "1"
.AddItem "2"
End With
End Select


Application.EnableEvents = True


End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
The trigger for your code is the Click Event. There are many other trigger events that you could use (Exit, Change, etc) that might trigger the code at the correct time. If you place your cursor within the code for that combo box, look at the VB Combo Box on the Right (should read "Click").
 
Upvote 0
Sorry for the delay in reading this. I'm finally back to working on this part of the project. I do have it set to "click", just like all the others. All other combo boxes are working perfectly.
This is the offending cb: Private Sub cbNS1_Click()
 
Upvote 0

Forum statistics

Threads
1,203,044
Messages
6,053,185
Members
444,643
Latest member
Shipwreck818

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top