Error message for empty listbox

  • hI PEOPLE,


    I JUST WANTED TO KNOW THE ANSWER TO A SIMPLE QUESTION, HOW DO I GET AN ERROR MESSAGE TO APPEAR IF NO ITEM IN A LIST BOX IS SELECTED ON PRESSING AN OK BUTTON ON THE FORM. COULD YOU HELP ME ASAP!! THANKZ.

  • Re: Error message for empty listbox


    Hi,


    This will check either the ListIndex or the Selected properties depending upon the Multiselect properties of the listbox.
    [vba]Private Sub CommandButton1_Click()


    Dim blnSelected As Boolean
    Dim intIndex As Integer

    If ListBox1.MultiSelect = fmMultiSelectSingle Then
    If ListBox1.ListIndex < 0 Then
    MsgBox "Please Select an item"
    End If
    Else
    For intIndex = 0 To ListBox1.ListCount - 1
    If ListBox1.Selected(intIndex) Then
    blnSelected = True
    Exit For
    End If
    Next
    If Not blnSelected Then
    MsgBox "Please Select an item"
    End If
    End If

    End Sub[/vba]

    [h4]Cheers
    Andy
    [/h4]

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!