473,543 Members | 2,488 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.lstTi tles) 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.Li stIndex <> -1 Then
...

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

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

If Not IsNull(Me.lstTi tles) 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.Li stIndex <> -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 "multiselec t," 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.lstTi tles) 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.Li stCount-1

if Me.lstTitles.Co lumn(intCtr).Se lected = 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.Li stCount-1

if Me.lstTitles.Co lumn(intCtr).Se lected = 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 getTheFirstSele cted(theList As ListBox, Optional
number) As String
Dim it As Long
If IsMissing(numbe r) Then
it = theList.ItemsSe lected(0)
Else
it = number
End If
getTheFirstSele cted = theList.ItemDat a(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
5844
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() { alert('Clicked MOVE button...'); var AvailableLB = document.getElementById("available");
0
1069
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 specifications is that the first possible record should be selected. It worked fine until the client decided that when they single click on the...
7
2001
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 listbox loads info: Private Sub Form_Open(Cancel As Integer) TabControl.Value = 0 Tab_Label1.Caption = "Select Alternatives from the Select List"...
2
10671
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 out is how to display an error, eg. "Please make a selection" if nothing is selected and the "Select" button is clicked. I'm trying an If Then Else...
4
5090
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 address book on the left, and you build the message recipients on the right. * an asp:button that, when clicked, fires off some code to create and...
2
2906
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
4073
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 and listbox are unbound. The listbox rowsource is a value list. The list box has about sixty items in it. Each item in the list box corresponds to...
1
4013
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 are not bound, I select from the bottom set and add to the top set which works fine, but now i decide to remove an item from the top set. when i...
5
2835
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 is what the ListBox uses for its display. Correct?
0
7590
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7735
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7347
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7688
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5885
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3391
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1817
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
968
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
636
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.