none
Is it easier to test if a combo or list box has NOT selected a value? Access 2016 win 10 pro. RRS feed

  • Question

  • I have used code to get the selected value of a combo box, and the one or more values selected in a List Box.

    This is a little different for me.    

    The Access 2016, win 10 pro VBA code will branch based on if the control DOES NOT have a value selected.

    I will have to test at least 2 of the 3 controls.  Due to at least one control has been selected.   

    If I use the List box controls, the list box will be set to ONLY select one value.

    Mark J


    Mark J

    Thursday, September 26, 2019 6:34 AM

Answers

  • If no item has been selected, the ListIndex of a combo box/list box equals -1. So you could use code like this:

        If Me.Combo1.ListIndex + Me.List1.ListIndex + Me.List2.ListIndex = -3 Then 
            ' No item selected in any of the three controls
            ...
        End If


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by PuzzledByWord Thursday, September 26, 2019 9:58 PM
    Thursday, September 26, 2019 11:38 AM

All replies

  • If no item has been selected, the ListIndex of a combo box/list box equals -1. So you could use code like this:

        If Me.Combo1.ListIndex + Me.List1.ListIndex + Me.List2.ListIndex = -3 Then 
            ' No item selected in any of the three controls
            ...
        End If


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by PuzzledByWord Thursday, September 26, 2019 9:58 PM
    Thursday, September 26, 2019 11:38 AM
  • Hans Vogelaar,

    Thanks again.    You are so helpful.   

    I could NOT believe it could be so simple.

    Mark J


    Mark J

    Thursday, September 26, 2019 10:00 PM