how do i display a value in a user form as a result of a selectio.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to get a value to return in a label within a user form once an
option in a combobox is selected.

This is how I have tried it:

With cboTariff2

.AddItem "50006"
.AddItem "50002"
.AddItem "50005"

End With

If cboTariff2 = 50006 Then
Label74 = "£10.58"

ElseIf cboTariff2.Text = "50002" Then
Label74 = "£11.51"

ElseIf cboTariff2.Text = "50005" Then
Label74 = "£11.85"

End If
 
Try .Value

With cboTariff2

.AddItem "50006"
.AddItem "50002"
.AddItem "50005"

End With

If cboTariff2.Value = "50006" Then
Label74 = "£10.58"

ElseIf cboTariff2.Value = "50002" Then
Label74 = "£11.51"

ElseIf cboTariff2.Value = "50005" Then
Label74 = "£11.85"

End If

Mike F
 
Private Sub cboTariff2_click()
If cboTariff2 = 50006 Then
Label74 = "£10.58"

ElseIf cboTariff2.Text = "50002" Then
Label74 = "£11.51"

ElseIf cboTariff2.Text = "50005" Then
Label74 = "£11.85"

End If
End Sub
 
Noticed you left the quotes of the first check

The key point was, you can't set the values in the list and handle the
selection in the same routine. Load the list in the Userform_initialize()
event and use the click event to handle the selection.

Private Sub cboTariff2_click()
If cboTariff2 = "50006" Then
Label74 = "£10.58"

ElseIf cboTariff2.Text = "50002" Then
Label74 = "£11.51"

ElseIf cboTariff2.Text = "50005" Then
Label74 = "£11.85"

End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top