473,399 Members | 3,038 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Listbox - how to tell if item unselected?

Using 2003. How do I tell if a selected item on a multi-select listbox
is now unselected? If a user unselects an item, I want to prompt them
that they've unselected it. No prompt if they're selecting an item.

I tried the following code but it displays the test message whether
they're selecting or unselecting:

For intRow = 1 To Me.lstEmployees.ListCount - 1
If Me.lstEmployees.Selected(intRow) = False Then
MsgBox "Previously selected"
Exit For
End If
Next intRow

Thanks for any help or advice.

Jan 12 '06 #1
3 5728
See if this example does what you want.

Private Sub List0_BeforeUpdate(Cancel As Integer)
Dim varItem As Variant, bolItemSelected As Boolean
For Each varItem In Me.List0.ItemsSelected
If varItem = Me.List0.ListIndex Then
bolItemSelected = True
End If
Next
If bolItemSelected Then
MsgBox "You just selected the item."
Else
MsgBox "You just unselected the item."
End If
End Sub

The ListIndex will be at the location you just clicked, so if the item you
just clicked is in the ItemsSelected list then you just selected the item.
If it's not in the list, you just deselected the item.

--
Wayne Morgan
MS Access MVP
<ma**********@hotmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Using 2003. How do I tell if a selected item on a multi-select listbox
is now unselected? If a user unselects an item, I want to prompt them
that they've unselected it. No prompt if they're selecting an item.

I tried the following code but it displays the test message whether
they're selecting or unselecting:

For intRow = 1 To Me.lstEmployees.ListCount - 1
If Me.lstEmployees.Selected(intRow) = False Then
MsgBox "Previously selected"
Exit For
End If
Next intRow

Thanks for any help or advice.

Jan 12 '06 #2
That did it. Thank you very much.

Jan 12 '06 #3

You can improve performance the merest smidgeon of a touch by changing

If varItem = Me.List0.ListIndex Then
bolItemSelected = True
End If

to
If varItem = Me.List0.ListIndex Then
bolItemSelected = True
Exit For
End If
--

Terry Kreft
"Wayne Morgan" <co***************************@hotmail.com> wrote in message
news:v1***************@newssvr12.news.prodigy.com. ..
See if this example does what you want.

Private Sub List0_BeforeUpdate(Cancel As Integer)
Dim varItem As Variant, bolItemSelected As Boolean
For Each varItem In Me.List0.ItemsSelected
If varItem = Me.List0.ListIndex Then
bolItemSelected = True
End If
Next
If bolItemSelected Then
MsgBox "You just selected the item."
Else
MsgBox "You just unselected the item."
End If
End Sub

The ListIndex will be at the location you just clicked, so if the item you
just clicked is in the ItemsSelected list then you just selected the item.
If it's not in the list, you just deselected the item.

--
Wayne Morgan
MS Access MVP
<ma**********@hotmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Using 2003. How do I tell if a selected item on a multi-select listbox
is now unselected? If a user unselects an item, I want to prompt them
that they've unselected it. No prompt if they're selecting an item.

I tried the following code but it displays the test message whether
they're selecting or unselecting:

For intRow = 1 To Me.lstEmployees.ListCount - 1
If Me.lstEmployees.Selected(intRow) = False Then
MsgBox "Previously selected"
Exit For
End If
Next intRow

Thanks for any help or advice.


Jan 13 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Andrew | last post by:
I'm having a major problem with a databound listbox in C#. In the constructor for the form I am trying to pre-select some of the items based in information in the database. When I step through the...
10
by: SueB | last post by:
Hi. Is there a way to "unselect" items in a listbox, programmatically? Here's what I want to do (and I've been trying to to this while debugging the form, but I've been unsuccessful) ... I...
1
by: Dan Bass | last post by:
I'm looking to develop a listbox with in-place editing where as each item is selected, it grows to fit in all the text boxes. When the item is deselected, it shrinks back to its original size. The...
4
by: Fernando Lopes | last post by:
Hi. I have a page with a usercontrol. In this UC, I have two ListBoxes and two buttons. When i click in one button, i get the selected item in the listbox. How can i validate, using validators,...
18
by: Dave Sauny | last post by:
Ok, its a friday, I'm at work and I cant get this to work: I have 3 listboxes on one tab control page. when i select an item in listbox1 i want whatever is selected on the other 2 listboxes...
0
by: tshad | last post by:
I have the following listbox: <asp:ListBox ID="Positions" SelectionMode="single" Rows="8" Width="600" runat="server"/> I also have the following traces: trace.warn("Positions.SelectedValue...
1
by: John | last post by:
Using Access 2007 I find that, on opening a form, a listbox control always displays one of the values in the list, even if no value has been selected. Thus, the first value in the list is...
1
by: Gerardo ARnaez | last post by:
Hi. I am writing a program to help determine coumadin regimens to look at the code: http://sourceforge.net/projects/coumadinregimen/ The issue is that I have a variable that I want the use to...
2
by: vinod allapu | last post by:
hi all, i am trying to generate a report, iam using sql server 2000 and Asp.net 2.0. First to select the columns iam using the list box... as we can order by the query result from the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.