Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default Trapping NO selections

"Otto Moehrbach" wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default Trapping NO selections

Rob
Thanks for the help. You guys are invaluable. Otto
"Rob Bovey" wrote in message
...
"Otto Moehrbach" wrote in message
...
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




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Trapping NO selections

Yes.

--
Regards,
Tom Ogilvy

"Otto Moehrbach" wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default 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" wrote in message
...
Yes.

--
Regards,
Tom Ogilvy

"Otto Moehrbach" wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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" wrote in message
...
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" wrote in message
...
Yes.

--
Regards,
Tom Ogilvy

"Otto Moehrbach" wrote in message
...
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








  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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" wrote in message
...
Yes.

--
Regards,
Tom Ogilvy

"Otto Moehrbach" wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default 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" wrote in message
...
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" wrote in message
...
Yes.

--
Regards,
Tom Ogilvy

"Otto Moehrbach" wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Trapping NO selections

for the multiselect property set to fmMultiSelectSingle - yes.

--
Regards,
Tom Ogilvy


"Otto Moehrbach" wrote in message
...
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" wrote in message
...
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" wrote in message
...
Yes.

--
Regards,
Tom Ogilvy

"Otto Moehrbach" wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default Trapping NO selections

Thanks Tom. Otto
"Tom Ogilvy" wrote in message
...
for the multiselect property set to fmMultiSelectSingle - yes.

--
Regards,
Tom Ogilvy


"Otto Moehrbach" wrote in message
...
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" wrote in message
...
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" wrote in message
...
Yes.

--
Regards,
Tom Ogilvy

"Otto Moehrbach" wrote in message
...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
error trapping [email protected] Excel Programming 2 January 20th 05 10:07 PM
Trapping #NAME? question Stuart[_5_] Excel Programming 7 February 29th 04 02:52 PM
trapping error RobcPettit Excel Programming 2 January 30th 04 03:37 AM
Error Trapping Neil Excel Programming 1 January 5th 04 04:38 PM
Trapping the mouse Sam K Excel Programming 1 July 27th 03 02:55 PM


All times are GMT +1. The time now is 12:58 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"