473,387 Members | 1,502 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,387 software developers and data experts.

Listbox Value is Null when listbox is clicked

I have a multi-selectable listbox named lstTitles.
In the OnClick event I had the following:

If Not IsNull(Me.lstTitles) Then
' do something with list selection
Else
' do something else
End If

This worked when I wrote it and has continued to work since...until
today.
Now when I click on the listbox, it's Value is Null. The ListIndex
property is set to the row that I clicked on, but lstTitles.Value is
always Null.
I worked around this using
If Me.lstTitles.ListIndex <> -1 Then
...

but I'm curious if anyone could tell me why the original code would
suddenly stop working.

Nov 13 '05 #1
5 16399
"RBohannon" <ra*****@hotmail.com> wrote in
news:11**********************@g47g2000cwa.googlegr oups.com:
I have a multi-selectable listbox named lstTitles.
In the OnClick event I had the following:

If Not IsNull(Me.lstTitles) Then
' do something with list selection
Else
' do something else
End If

This worked when I wrote it and has continued to work
since...until today.
Now when I click on the listbox, it's Value is Null. The
ListIndex property is set to the row that I clicked on, but
lstTitles.Value is always Null.
I worked around this using
If Me.lstTitles.ListIndex <> -1 Then
...

but I'm curious if anyone could tell me why the original code
would suddenly stop working.


What's your rowsource?

Perhaps you've changed the bound column and that column has no data
in it.

Actually, just noticing that you said "multiselect," I believe
multiselect listboxes are *always* Null, no matter whether there is
a selection or not.

How could you meaningfully return a single value from a listbox with
more than one item selected?

You have to process the .ItemsSelected collection to figure out what
the selected values are. To see if it's not got anything selected,
just check the .Count of .ItemsSelected.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #2
RBohannon wrote:
I have a multi-selectable listbox named lstTitles.
In the OnClick event I had the following:

If Not IsNull(Me.lstTitles) Then
' do something with list selection
Else
' do something else
End If

This worked when I wrote it and has continued to work since...until
today.


I've run into that with multi-select list boxes. I prefer to just run
through the rows in the box and count how many for which the selected
property is true, ie:

dim intCtr as integer
dim intSelected as integer

intSelected = 0 'int are initialized as 0, so may not be required

for intCtr = 0 to Me.lstTitles.ListCount-1

if Me.lstTitles.Column(intCtr).Selected = True _
intSelected = intSelected + 1

Next intCtr

If intSelected > 0 Then
' do something with list selection
Else
' do something else
End If

--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Nov 13 '05 #3
Tim Marshall wrote:

OOPS THAT WAS AIR CODE - FORGOT THE "THEN" IN THE IF STATEMENT!!!!

Revised below:
dim intCtr as integer
dim intSelected as integer

intSelected = 0 'int are initialized as 0, so may not be required

for intCtr = 0 to Me.lstTitles.ListCount-1

if Me.lstTitles.Column(intCtr).Selected = True Then _
intSelected = intSelected + 1

Next intCtr

If intSelected > 0 Then
' do something with list selection
Else
' do something else
End If

--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Nov 13 '05 #4
Tim Marshall wrote:
I've run into that with multi-select list boxes. I prefer to just run
through the rows in the box and count how many for which the selected
property is true, ie:


And then, you could use the ItemsSelected collection of the listbox.

I use this routine if I want the first selected item:

Private Function getTheFirstSelected(theList As ListBox, Optional
number) As String
Dim it As Long
If IsMissing(number) Then
it = theList.ItemsSelected(0)
Else
it = number
End If
getTheFirstSelected = theList.ItemData(it)
End Function

--
Bas Cost Budde, Holland

Nov 13 '05 #5
Thank you all for your responses.

Randy

Nov 13 '05 #6

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

Similar topics

2
by: ashkaan57 | last post by:
Hi, I have two listboxes and want to move a set of selcted items from the listbox on the left moved to the listbox on the right when a button is pressed: function RightButton_OnClick() {...
0
by: Stubble | last post by:
I have code that selects records in a listbox called based on the value typed in a textbox called txtVendor like the windows help that narrows the possiblities as the user types. One of the...
7
by: Colleyville Alan | last post by:
I have an app in which users are displayed a list of mutual fund from which they can choose. There is a listbox embedded in a two-tabbed notebook control. When the form is initally opened, the...
2
by: jpalmerx | last post by:
Hi, I have a form in Access with a listbox containing some choices. There is a "Select" button underneath that runs a macro opening a form that acts on the selected value. What I can't figure...
4
by: Bob P. | last post by:
Hello, I have a page with: * two side-by-side asp:listboxes and two arrow asp:buttons allowing users to add/remove email addresses between them -- very much like Outlook, where you have the...
2
by: teo | last post by:
I have a Listbox, if I set EnableViewStarte = False the AutopostaBack fired by SelectedIndexChanged doesn't work. The 'SelectedIndexChanged' event should call
5
by: Matthew Wells | last post by:
I have a listbox set to simple multi select. For this example, users only select one item at a time. I have command buttons on the form for First, Previous, Next, Last, New (record). The form...
1
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which...
5
by: Academia | last post by:
(If you've seen this in the drawing NG, sorry. I inadvertently sent it there.) I have a listbox populated with Objects. The Class has a String field that ToString returns. I assume that...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.