0
votes

I have a UserForm with some radio buttons and two single column ListBox's. I'm having trouble returning the value from the second ListBox under certain circumstances.

If the user selects one of the radio buttons they get a series of items to select from in the first ListBox. Once they select from the first ListBox, the 2nd ListBox gets populated with items.

If they select the other radio buttons, the two ListBox's just get populated with a single value "Not Applicable" and I'm selecting it straight away.

This is the code I'm using to set the two ListBox's up with "Not Applicable"

ListBox_First.Clear
ListBox_Second.Clear
ListBox_First.List = Array("Not Applicable")
ListBox_First.Selected(0) = True
ListBox_Second.List = Array("Not Applicable")
ListBox_Second.Selected(0) = True

This is my code to get the value selected

Dim firstValue As String
Dim secondValue As String
firstValue = ListBox_First.Value
secondValue = ListBox_Second.Value

firstValue is ok as it equals "Not Applicable", however secondValue is equal to "". When you look at the form, the value in each ListBox looks like it's selected so I don't understand why it's blank. I have checked the ListCount property and each ListBox only has one item so it should be correctly selected.

If I manually select "Not Applicable" in the second ListBox using the mouse is works fine, but I'm trying to avoid the user having to select it when it's the only value.

I don't know if this is a bug or if I've done something wrong with my code.

I'm working with a product called WRQ Reflections.

1

1 Answers

0
votes

The value is recognized by adding the setfocus command.

firstValue = ListBox_First.Value
ListBox_Second.SetFocus
secondValue = ListBox_Second.Value