PDA

View Full Version : get the value for list box into code



buster_gonad
10-31-2011, 11:08 AM
Hi,

New to vba

I have been given help to devise a list box of options and I want to get the selected value for the list box into the following code:-

Select Case result
Case Listbox value???
'
' Send email as is
'
Item.Subject = Item.Subject
Cancel = False

Case Listbox value???
'
' Send message restricted
'
Item.Subject = "restricted"+Item.Subject

Cancel = False

Case Listbox value???
'
' Send message restricted staff
'
Item.Subject = "restricted staff"

Cancel = False

Case Listbox value???:
'
' do not send the email
'
Cancel = True


End Select
End If
End Sub

I would appreciate any help in this area

Cheers

JP2112
11-02-2011, 06:58 AM
Please use [ VBA ] tags when posting VBA code.

ListBox.Value will return the currently selected item, as long as MultiSelect is set to fmMultiSelectSingle.

buster_gonad
11-03-2011, 11:14 AM
Please use [ VBA ] tags when posting VBA code.

ListBox.Value will return the currently selected item, as long as MultiSelect is set to fmMultiSelectSingle.

Thanks for the above but can you advise me as to what code I need on the button click to inniate the correct select option

Thanking you in adavnce

JP2112
11-04-2011, 09:58 AM
I'm confused, what exactly do you need?

Only you know the possible values in your listbox. So only you can complete the code.

ListBox.Value gives you the selected value. Just plug that into your Select Case Statement. Something like this:


Select Case ListBox.Value
Case "apples"
' do something if "apples" is selected
Case "oranges"
' do something if "oranges" is selected
End Select