Consulting

Results 1 to 4 of 4

Thread: get the value for list box into code

  1. #1

    get the value for list box into code

    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

  2. #2
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    Please use [ VBA ] tags when posting VBA code.

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

    Read the FAQ
    Getting free help on the web
    My website
    Please use [vba][/vba] tags when posting code

  3. #3

    get list box option into code

    Quote Originally Posted by JP2112
    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

  4. #4
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    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:

    [VBA]
    Select Case ListBox.Value
    Case "apples"
    ' do something if "apples" is selected
    Case "oranges"
    ' do something if "oranges" is selected
    End Select
    [/VBA]
    Regards,
    JP

    Read the FAQ
    Getting free help on the web
    My website
    Please use [vba][/vba] tags when posting code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •