By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,826 Members | 2,384 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,826 IT Pros & Developers. It's quick & easy.

Listbox Value is Null when listbox is clicked

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
Thank you all for your responses.

Randy

Nov 13 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.