Results 1 to 4 of 4

Thread: [RESOLVED] Pop up messagebox when no selection in listbox

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Resolved [RESOLVED] Pop up messagebox when no selection in listbox

    I have item in the listbox.. I am trying to pop up the messagebox when no selection item were made in the listbox. How to do that?

    Code:
    For c = 0 To ListBox1.ListCount - 1
    
    Next c

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Pop up messagebox when no selection in listbox

    Code:
    Private Sub Command1_Click()
    Dim i As Long
    Dim blnSelected As Boolean
    For i = 0 To List1.ListCount - 1
        If List1.Selected(i) = True Then
           blnSelected = True
           Exit For
        End If
    Next
    If blnSelected = False Then
       MsgBox "No selections made"
    End If
    End Sub
    Last edited by Hack; Jun 17th, 2008 at 12:55 PM.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: Pop up messagebox when no selection in listbox

    This really help me

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [RESOLVED] Pop up messagebox when no selection in listbox

    Since you only need to check for at least one selection, you don't need it to loop through the entire listbox unless it can't find anything selected.

    I edited what I posted and added an Exit For if it finds at least one match. That is more efficient.

Posting Permissions

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



Click Here to Expand Forum to Full Width