472,371 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,371 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 16181
"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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

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.