[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.excel.programming

Listbox none selected feature

Mike Milligan

12/12/2006 6:26:00 PM

It seems that there is no property for determining if a listbox
(multiselect) has at least one selection. Browsing this board I find the
common method below for accomplishing the task, but was surprised that no
property exists. Is it true?

For i = 0 to .listcount - 1
If .selected(i) = true then
'do something'
End if
Next i

Mike


4 Answers

theSquirrel

12/12/2006 8:37:00 PM

0

I have used this code before to determine if there is a selection:

If Me.lstManager.ListIndex = -1 Then
MsgBox "You don't have a Manager selected, please make a
selection and try again.", _
vbExclamation, "Make a Selection"
End If

This doesn't count the number of selections, but does detect if there
is a selection.

You can also use this:

If Me.lstManager.Selected = True then
'Do this code
End if

If selected = true, at least one value is selected. Likewise, if
selected = false, no selections have been made. This however only
applies to list boxes with multiselect = true.

Hope that helps

theSquirrel



On Dec 12, 10:25 am, "Mike Milligan" <mike.milli...@ngc.com> wrote:
> It seems that there is no property for determining if a listbox
> (multiselect) has at least one selection. Browsing this board I find the
> common method below for accomplishing the task, but was surprised that no
> property exists. Is it true?
>
> For i = 0 to .listcount - 1
> If .selected(i) = true then
> 'do something'
> End if
> Next i
>
> Mike

Mike Milligan

12/12/2006 9:12:00 PM

0

I thought of listindex, but ListIndex cannot be used with a 'multiselect'
listbox, which I have.

Thanks anyway.
Mike

<thesquirrel@gmail.com> wrote in message
news:1165955848.264426.79050@n67g2000cwd.googlegroups.com...
>I have used this code before to determine if there is a selection:
>
> If Me.lstManager.ListIndex = -1 Then
> MsgBox "You don't have a Manager selected, please make a
> selection and try again.", _
> vbExclamation, "Make a Selection"
> End If
>
> This doesn't count the number of selections, but does detect if there
> is a selection.
>
> You can also use this:
>
> If Me.lstManager.Selected = True then
> 'Do this code
> End if
>
> If selected = true, at least one value is selected. Likewise, if
> selected = false, no selections have been made. This however only
> applies to list boxes with multiselect = true.
>
> Hope that helps
>
> theSquirrel
>
>
>
> On Dec 12, 10:25 am, "Mike Milligan" <mike.milli...@ngc.com> wrote:
>> It seems that there is no property for determining if a listbox
>> (multiselect) has at least one selection. Browsing this board I find the
>> common method below for accomplishing the task, but was surprised that no
>> property exists. Is it true?
>>
>> For i = 0 to .listcount - 1
>> If .selected(i) = true then
>> 'do something'
>> End if
>> Next i
>>
>> Mike
>


theSquirrel

12/12/2006 9:55:00 PM

0

The second part of my post listed this code as well...

You can also use this:

If Me.lstManager.Selected = True then
'Do this code
End if

This will be true if there is a selection, and false if there is no
selection.

theSquirrel

On Dec 12, 1:11 pm, "Mike Milligan" <mike.milli...@ngc.com> wrote:
> I thought of listindex, but ListIndex cannot be used with a 'multiselect'
> listbox, which I have.
>
> Thanks anyway.
> Mike
>
> <thesquir...@gmail.com> wrote in messagenews:1165955848.264426.79050@n67g2000cwd.googlegroups.com...
>
>
>
> >I have used this code before to determine if there is a selection:
>
> > If Me.lstManager.ListIndex = -1 Then
> > MsgBox "You don't have a Manager selected, please make a
> > selection and try again.", _
> > vbExclamation, "Make a Selection"
> > End If
>
> > This doesn't count the number of selections, but does detect if there
> > is a selection.
>
> > You can also use this:
>
> > If Me.lstManager.Selected = True then
> > 'Do this code
> > End if
>
> > If selected = true, at least one value is selected. Likewise, if
> > selected = false, no selections have been made. This however only
> > applies to list boxes with multiselect = true.
>
> > Hope that helps
>
> > theSquirrel
>
> > On Dec 12, 10:25 am, "Mike Milligan" <mike.milli...@ngc.com> wrote:
> >> It seems that there is no property for determining if a listbox
> >> (multiselect) has at least one selection. Browsing this board I find the
> >> common method below for accomplishing the task, but was surprised that no
> >> property exists. Is it true?
>
> >> For i = 0 to .listcount - 1
> >> If .selected(i) = true then
> >> 'do something'
> >> End if
> >> Next i
>
> >> Mike- Hide quoted text -- Show quoted text -

Mike Milligan

12/12/2006 10:32:00 PM

0

I receive an "argument not optional" error highlighting '.Selected' as the
offending property.



<thesquirrel@gmail.com> wrote in message
news:1165960471.102415.214970@f1g2000cwa.googlegroups.com...
> The second part of my post listed this code as well...
>
> You can also use this:
>
> If Me.lstManager.Selected = True then
> 'Do this code
> End if
>
> This will be true if there is a selection, and false if there is no
> selection.
>
> theSquirrel
>
> On Dec 12, 1:11 pm, "Mike Milligan" <mike.milli...@ngc.com> wrote:
>> I thought of listindex, but ListIndex cannot be used with a 'multiselect'
>> listbox, which I have.
>>
>> Thanks anyway.
>> Mike
>>
>> <thesquir...@gmail.com> wrote in
>> messagenews:1165955848.264426.79050@n67g2000cwd.googlegroups.com...
>>
>>
>>
>> >I have used this code before to determine if there is a selection:
>>
>> > If Me.lstManager.ListIndex = -1 Then
>> > MsgBox "You don't have a Manager selected, please make a
>> > selection and try again.", _
>> > vbExclamation, "Make a Selection"
>> > End If
>>
>> > This doesn't count the number of selections, but does detect if there
>> > is a selection.
>>
>> > You can also use this:
>>
>> > If Me.lstManager.Selected = True then
>> > 'Do this code
>> > End if
>>
>> > If selected = true, at least one value is selected. Likewise, if
>> > selected = false, no selections have been made. This however only
>> > applies to list boxes with multiselect = true.
>>
>> > Hope that helps
>>
>> > theSquirrel
>>
>> > On Dec 12, 10:25 am, "Mike Milligan" <mike.milli...@ngc.com> wrote:
>> >> It seems that there is no property for determining if a listbox
>> >> (multiselect) has at least one selection. Browsing this board I find
>> >> the
>> >> common method below for accomplishing the task, but was surprised that
>> >> no
>> >> property exists. Is it true?
>>
>> >> For i = 0 to .listcount - 1
>> >> If .selected(i) = true then
>> >> 'do something'
>> >> End if
>> >> Next i
>>
>> >> Mike- Hide quoted text -- Show quoted text -
>