I’ve got a problem with a user form which has two radio buttons and two combo boxes. The rowsource depends upon which radio button the user clicks. (See attached file.)
The user chooses a radio button and can then select a value in either combo box. The other combo box then picks up the appropriate value & a description appears in the label.
The problem comes in when the user decides that they’re looking in the wrong place & they click the other radio button. The combo box called cmb_name picks up the first value in the list it has just been using as a rowsource. When the user clicks on it to get the drop-down list, the correct values are there.
The other combo-box (cmb_prn) is behaving itself properly. I suspect I’m missing something really simple but it is annoying me. I would appreciate help with this.
Thank you
Oops! I don't appear to have succeeded in uploading the file!
Ah, well, here is the code instead:
HTML Code:
Dim row_number As Integer
Dim the_row As Integer
Dim Range3P As Range
Dim RangeOP As Range
Dim Range3N As Range
Dim RangeON As Range
Dim t As Integer
Dim s As Integer
Private Sub UserForm_Click()
End Sub
Private Sub cmb_prn_Change()
Call Show_by_PRN
End Sub
Private Sub cmd_cancel_Click()
UserForm1.Hide
Unload UserForm1
End Sub
Private Sub opt_other_Click()
If opt_other = True Then
opt_ts = False
End If
cmb_name = ""
cmb_name.RowSource = vbNullString
cmb_prn.RowSource = vbNullString
cmb_prn = ""
lbl_acty_descrip.Caption = ""
If opt_other = True Then
Call FindInOther
End If
End Sub
Private Sub opt_ts_Click()
If opt_ts = True Then
opt_other = False
End If
'cmb_name_search.Clear
cmb_name = ""
cmb_name.RowSource = vbNullString
cmb_prn.RowSource = vbNullString
cmb_prn = ""
lbl_acty_descrip.Caption = ""
If opt_ts = True Then
Call FindInTS
End If
End Sub
Private Sub UserForm_Initialize()
With UserForm1
ShowModal = False
End With
opt_ts = True
End Sub
Private Sub cmb_name_Click()
Call Show_by_name
End Sub
Sub Show_by_name()
If cmb_name.ListCount = 0 Then
row_number = 0
Else
row_number = cmb_name.ListIndex
End If
s = row_number + 5
Cells(s, 2).Activate
cmb_prn = Cells(s, 2).Text
lbl_acty_descrip.Caption = Cells(s, 9).Text
End Sub
Sub Show_by_PRN()
If cmb_prn.ListCount = 0 Then
the_row = 0
Else
the_row = cmb_prn.ListIndex
End If
t = the_row + 5
Cells(t, 2).Activate
cmb_name = Cells(t, 5).Text
lbl_acty_descrip.Caption = Cells(t, 9).Text
End Sub
Sub FindInTS()
Sheets("ts").Select
Cells(5, 5).Select
cmb_prn.RowSource = "B5: B10"
cmb_name.RowSource = "E5: E10"
Sheets("ts").Activate
End Sub
Sub FindInOther()
Sheets("other").Select
Cells(5, 5).Select
cmb_prn.RowSource = "B5:B10"
cmb_name.RowSource = "E5:E10"
Sheets("other").Activate
End Sub
(The data source is on two sheets of an Excel workbook, in columns B & E.)