+ Reply to Thread
Results 1 to 10 of 10

Trapping NO selections

  1. #1
    Otto Moehrbach
    Guest

    Trapping NO selections

    Excel 2002, WinXP
    I have a UF with a multi-selection ListBox, lbNMFee.
    I want to act on the instance wherein the user makes no selections in the
    ListBox. I have the following argument that is True if no selections are
    made. This code is in the beginning of the macro that is called by the OK
    button click.
    Is this correct? Thanks for your help. Otto

    If UFMgtFee.lbNMFee.ListIndex = -1 Then



  2. #2
    Rob Bovey
    Guest

    Re: Trapping NO selections

    "Otto Moehrbach" <[email protected]> wrote in message
    news:[email protected]...
    > Excel 2002, WinXP
    > I have a UF with a multi-selection ListBox, lbNMFee.
    > I want to act on the instance wherein the user makes no selections in the
    > ListBox. I have the following argument that is True if no selections are
    > made. This code is in the beginning of the macro that is called by the OK
    > button click.
    > Is this correct? Thanks for your help. Otto
    >
    > If UFMgtFee.lbNMFee.ListIndex = -1 Then


    Hi Otto,

    No, that won't work with a multi-select listbox. In this case you have
    to loop through each item in the list and check its Selected property. If
    all Selected properties return False then nothig is selected. Here's an
    example:

    Private Sub CommandButton1_Click()
    Dim bSelected As Boolean
    Dim lIndex As Long
    For lIndex = 0 To ListBox1.ListCount - 1
    If ListBox1.Selected(lIndex) Then bSelected = True
    Next lIndex
    If Not bSelected Then MsgBox "Nothing selected."
    End Sub

    --
    Rob Bovey, Excel MVP
    Application Professionals
    http://www.appspro.com/

    * Take your Excel development skills to the next level.
    * Professional Excel Development
    http://www.appspro.com/Books/Books.htm



  3. #3
    Tom Ogilvy
    Guest

    Re: Trapping NO selections

    Yes.

    --
    Regards,
    Tom Ogilvy

    "Otto Moehrbach" <[email protected]> wrote in message
    news:[email protected]...
    > Excel 2002, WinXP
    > I have a UF with a multi-selection ListBox, lbNMFee.
    > I want to act on the instance wherein the user makes no selections in the
    > ListBox. I have the following argument that is True if no selections are
    > made. This code is in the beginning of the macro that is called by the OK
    > button click.
    > Is this correct? Thanks for your help. Otto
    >
    > If UFMgtFee.lbNMFee.ListIndex = -1 Then
    >
    >




  4. #4
    Otto Moehrbach
    Guest

    Re: Trapping NO selections

    Tom
    Now I'm in a quandary. Bob says No and you say Yes. I tried the
    following code and I don't get the "Nothing" MsgBox when no selections are
    made. Help!! Otto
    If UFMgtFee.lbNMFee.ListIndex = -1 Then
    MsgBox = "Nothing"
    Unload UFMgtFee
    Else
    'Do stuff with the selections
    End If
    "Tom Ogilvy" <[email protected]> wrote in message
    news:O%[email protected]...
    > Yes.
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    > "Otto Moehrbach" <[email protected]> wrote in message
    > news:[email protected]...
    >> Excel 2002, WinXP
    >> I have a UF with a multi-selection ListBox, lbNMFee.
    >> I want to act on the instance wherein the user makes no selections in the
    >> ListBox. I have the following argument that is True if no selections are
    >> made. This code is in the beginning of the macro that is called by the
    >> OK
    >> button click.
    >> Is this correct? Thanks for your help. Otto
    >>
    >> If UFMgtFee.lbNMFee.ListIndex = -1 Then
    >>
    >>

    >
    >




  5. #5
    Tom Ogilvy
    Guest

    Re: Trapping NO selections

    Sorry - missed the Multi-selection part - see Rob's answer.

    for some reason I started reading on this line:
    >> I want to act on the instance wherein the user makes no selections in the
    > > ListBox.


    --
    Regards,
    Tom Ogilvy

    "Tom Ogilvy" <[email protected]> wrote in message
    news:O%[email protected]...
    > Yes.
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    > "Otto Moehrbach" <[email protected]> wrote in message
    > news:[email protected]...
    > > Excel 2002, WinXP
    > > I have a UF with a multi-selection ListBox, lbNMFee.
    > > I want to act on the instance wherein the user makes no selections in

    the
    > > ListBox. I have the following argument that is True if no selections

    are
    > > made. This code is in the beginning of the macro that is called by the

    OK
    > > button click.
    > > Is this correct? Thanks for your help. Otto
    > >
    > > If UFMgtFee.lbNMFee.ListIndex = -1 Then
    > >
    > >

    >
    >




  6. #6
    Otto Moehrbach
    Guest

    Re: Trapping NO selections

    Rob
    Thanks for the help. You guys are invaluable. Otto
    "Rob Bovey" <[email protected]> wrote in message
    news:[email protected]...
    > "Otto Moehrbach" <[email protected]> wrote in message
    > news:[email protected]...
    >> Excel 2002, WinXP
    >> I have a UF with a multi-selection ListBox, lbNMFee.
    >> I want to act on the instance wherein the user makes no selections in the
    >> ListBox. I have the following argument that is True if no selections are
    >> made. This code is in the beginning of the macro that is called by the
    >> OK button click.
    >> Is this correct? Thanks for your help. Otto
    >>
    >> If UFMgtFee.lbNMFee.ListIndex = -1 Then

    >
    > Hi Otto,
    >
    > No, that won't work with a multi-select listbox. In this case you have
    > to loop through each item in the list and check its Selected property. If
    > all Selected properties return False then nothig is selected. Here's an
    > example:
    >
    > Private Sub CommandButton1_Click()
    > Dim bSelected As Boolean
    > Dim lIndex As Long
    > For lIndex = 0 To ListBox1.ListCount - 1
    > If ListBox1.Selected(lIndex) Then bSelected = True
    > Next lIndex
    > If Not bSelected Then MsgBox "Nothing selected."
    > End Sub
    >
    > --
    > Rob Bovey, Excel MVP
    > Application Professionals
    > http://www.appspro.com/
    >
    > * Take your Excel development skills to the next level.
    > * Professional Excel Development
    > http://www.appspro.com/Books/Books.htm
    >
    >




  7. #7
    Otto Moehrbach
    Guest

    Re: Trapping NO selections

    Tom
    Thanks for that correction. I take it from what you said that your
    original response is correct for a 'MultiSelectSingle' ListBox. Is that
    correct? Otto
    "Tom Ogilvy" <[email protected]> wrote in message
    news:[email protected]...
    > Sorry - missed the Multi-selection part - see Rob's answer.
    >
    > for some reason I started reading on this line:
    >>> I want to act on the instance wherein the user makes no selections in
    >>> the
    >> > ListBox.

    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    > "Tom Ogilvy" <[email protected]> wrote in message
    > news:O%[email protected]...
    >> Yes.
    >>
    >> --
    >> Regards,
    >> Tom Ogilvy
    >>
    >> "Otto Moehrbach" <[email protected]> wrote in message
    >> news:[email protected]...
    >> > Excel 2002, WinXP
    >> > I have a UF with a multi-selection ListBox, lbNMFee.
    >> > I want to act on the instance wherein the user makes no selections in

    > the
    >> > ListBox. I have the following argument that is True if no selections

    > are
    >> > made. This code is in the beginning of the macro that is called by the

    > OK
    >> > button click.
    >> > Is this correct? Thanks for your help. Otto
    >> >
    >> > If UFMgtFee.lbNMFee.ListIndex = -1 Then
    >> >
    >> >

    >>
    >>

    >
    >




  8. #8
    Tom Ogilvy
    Guest

    Re: Trapping NO selections

    Otto,
    Sorry for the confusion. Hopefully by now you read my other post that said
    I had missed the part about the multi-select setting. Go with Rob's
    solution.

    I thought it was peculiar that you were asking this question - guess that
    should have tipped me off that I was missing something.

    --
    Regards,
    Tom Ogilvy

    "Otto Moehrbach" <[email protected]> wrote in message
    news:[email protected]...
    > Tom
    > Now I'm in a quandary. Bob says No and you say Yes. I tried the
    > following code and I don't get the "Nothing" MsgBox when no selections are
    > made. Help!! Otto
    > If UFMgtFee.lbNMFee.ListIndex = -1 Then
    > MsgBox = "Nothing"
    > Unload UFMgtFee
    > Else
    > 'Do stuff with the selections
    > End If
    > "Tom Ogilvy" <[email protected]> wrote in message
    > news:O%[email protected]...
    > > Yes.
    > >
    > > --
    > > Regards,
    > > Tom Ogilvy
    > >
    > > "Otto Moehrbach" <[email protected]> wrote in message
    > > news:[email protected]...
    > >> Excel 2002, WinXP
    > >> I have a UF with a multi-selection ListBox, lbNMFee.
    > >> I want to act on the instance wherein the user makes no selections in

    the
    > >> ListBox. I have the following argument that is True if no selections

    are
    > >> made. This code is in the beginning of the macro that is called by the
    > >> OK
    > >> button click.
    > >> Is this correct? Thanks for your help. Otto
    > >>
    > >> If UFMgtFee.lbNMFee.ListIndex = -1 Then
    > >>
    > >>

    > >
    > >

    >
    >




  9. #9
    Tom Ogilvy
    Guest

    Re: Trapping NO selections

    for the multiselect property set to fmMultiSelectSingle - yes.

    --
    Regards,
    Tom Ogilvy


    "Otto Moehrbach" <[email protected]> wrote in message
    news:[email protected]...
    > Tom
    > Thanks for that correction. I take it from what you said that your
    > original response is correct for a 'MultiSelectSingle' ListBox. Is that
    > correct? Otto
    > "Tom Ogilvy" <[email protected]> wrote in message
    > news:[email protected]...
    > > Sorry - missed the Multi-selection part - see Rob's answer.
    > >
    > > for some reason I started reading on this line:
    > >>> I want to act on the instance wherein the user makes no selections in
    > >>> the
    > >> > ListBox.

    > >
    > > --
    > > Regards,
    > > Tom Ogilvy
    > >
    > > "Tom Ogilvy" <[email protected]> wrote in message
    > > news:O%[email protected]...
    > >> Yes.
    > >>
    > >> --
    > >> Regards,
    > >> Tom Ogilvy
    > >>
    > >> "Otto Moehrbach" <[email protected]> wrote in message
    > >> news:[email protected]...
    > >> > Excel 2002, WinXP
    > >> > I have a UF with a multi-selection ListBox, lbNMFee.
    > >> > I want to act on the instance wherein the user makes no selections in

    > > the
    > >> > ListBox. I have the following argument that is True if no selections

    > > are
    > >> > made. This code is in the beginning of the macro that is called by

    the
    > > OK
    > >> > button click.
    > >> > Is this correct? Thanks for your help. Otto
    > >> >
    > >> > If UFMgtFee.lbNMFee.ListIndex = -1 Then
    > >> >
    > >> >
    > >>
    > >>

    > >
    > >

    >
    >




  10. #10
    Otto Moehrbach
    Guest

    Re: Trapping NO selections

    Thanks Tom. Otto
    "Tom Ogilvy" <[email protected]> wrote in message
    news:%[email protected]...
    > for the multiselect property set to fmMultiSelectSingle - yes.
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "Otto Moehrbach" <[email protected]> wrote in message
    > news:[email protected]...
    >> Tom
    >> Thanks for that correction. I take it from what you said that your
    >> original response is correct for a 'MultiSelectSingle' ListBox. Is that
    >> correct? Otto
    >> "Tom Ogilvy" <[email protected]> wrote in message
    >> news:[email protected]...
    >> > Sorry - missed the Multi-selection part - see Rob's answer.
    >> >
    >> > for some reason I started reading on this line:
    >> >>> I want to act on the instance wherein the user makes no selections in
    >> >>> the
    >> >> > ListBox.
    >> >
    >> > --
    >> > Regards,
    >> > Tom Ogilvy
    >> >
    >> > "Tom Ogilvy" <[email protected]> wrote in message
    >> > news:O%[email protected]...
    >> >> Yes.
    >> >>
    >> >> --
    >> >> Regards,
    >> >> Tom Ogilvy
    >> >>
    >> >> "Otto Moehrbach" <[email protected]> wrote in message
    >> >> news:[email protected]...
    >> >> > Excel 2002, WinXP
    >> >> > I have a UF with a multi-selection ListBox, lbNMFee.
    >> >> > I want to act on the instance wherein the user makes no selections
    >> >> > in
    >> > the
    >> >> > ListBox. I have the following argument that is True if no
    >> >> > selections
    >> > are
    >> >> > made. This code is in the beginning of the macro that is called by

    > the
    >> > OK
    >> >> > button click.
    >> >> > Is this correct? Thanks for your help. Otto
    >> >> >
    >> >> > If UFMgtFee.lbNMFee.ListIndex = -1 Then
    >> >> >
    >> >> >
    >> >>
    >> >>
    >> >
    >> >

    >>
    >>

    >
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1