Listbox value (1 Viewer)

kirkm

Registered User.
Local time
Tomorrow, 11:51
Joined
Oct 30, 2008
Messages
1,257
Hi, I have 3 listboxes on my form and Form Load code is

Code:
Private Sub Form_Load()
    Dim i As Integer
    For i = 1 To 100
        listPosFrom.AddItem i
        listPosTo.AddItem i
    Next
    List4.RowSource = "SELECT DISTINCT tblMain.Year FROM tblMain WHERE (((tblMain.Year)>='" & Me.OpenArgs & "'));"
End Sub

The listboxes show the expected values and change with their arrows.
But if I try and read that value in code, they are Null.

Debug Print List4 = Null
Debug Print List4.Value = Null

What am I doing wrong ?
Thanks.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 15:51
Joined
Oct 29, 2018
Messages
21,358
Are your listboxes multi select?
 

moke123

AWF VIP
Local time
Today, 18:51
Joined
Jan 11, 2013
Messages
3,852
The listboxes show the expected values and change with their arrows.
list boxes dont have arrows. Are you talking about combo boxes?
 

kirkm

Registered User.
Local time
Tomorrow, 11:51
Joined
Oct 30, 2008
Messages
1,257
No, that is I haven't set that property. Should be one item only.
 

kirkm

Registered User.
Local time
Tomorrow, 11:51
Joined
Oct 30, 2008
Messages
1,257
> list boxes dont have arrows. Are you talking about combo boxes?
No, they're definitely list boxes. Maybe they're not called arrows.. the things you click on to move through the items.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 15:51
Joined
Oct 29, 2018
Messages
21,358
No, that is I haven't set that property. Should be one item only.
Maybe it "should" be one item only, but maybe it's a good idea to check to make sure anyway.
 

kirkm

Registered User.
Local time
Tomorrow, 11:51
Joined
Oct 30, 2008
Messages
1,257
The multi select property shows "None" for all 3.
Really weird I can't find this via Google. The value I want is what's showing. I've looked at ListIndex but that says -1.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 15:51
Joined
Oct 29, 2018
Messages
21,358
The multi select property shows "None" for all 3.
Really weird I can't find this via Google. The value I want is what's showing. I've looked at ListIndex but that says -1.
Okay, next is to see what's in the following properties.

Row Source
Column Count
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 09:51
Joined
Jan 20, 2009
Messages
12,849
AddItem is for List RowSourceType only.
The RowSourceType needs to be Table/Query to use a Select.
 

moke123

AWF VIP
Local time
Today, 18:51
Joined
Jan 11, 2013
Messages
3,852
perhaps your talking about the scrollbar.

you are selecting an item in the list first right?
if you get -1 for listindex then nothing is selected.
 

kirkm

Registered User.
Local time
Tomorrow, 11:51
Joined
Oct 30, 2008
Messages
1,257
The row source For List4 is in Msg# and in Form Load, not a property entry. That ok ? Column count (on all 3) is 1.
Rowsource type for List4 is Table/Query and the others are Value/List
 

kirkm

Registered User.
Local time
Tomorrow, 11:51
Joined
Oct 30, 2008
Messages
1,257
> perhaps your talking about the scrollbar.
> you are selecting an item in the list first right?

Yes and yes. The items change as you scroll. That list stays on one item, as opposed to a dropdown list.
 

kirkm

Registered User.
Local time
Tomorrow, 11:51
Joined
Oct 30, 2008
Messages
1,257
> if you get -1 for listindex then nothing is selected.
OK. But there is a value in the list box. That's what I want to use in my botton event.
 

kirkm

Registered User.
Local time
Tomorrow, 11:51
Joined
Oct 30, 2008
Messages
1,257
> If you are getting null for the value and -1 for the listindex you have not selected an item in the list.
I've move the scrollbars so they show an item. Do I need to click on the item as well ? If so, thats an extrsa step that isn't obvious. Can it be avoided?
 

moke123

AWF VIP
Local time
Today, 18:51
Joined
Jan 11, 2013
Messages
3,852
> If you are getting null for the value and -1 for the listindex you have not selected an item in the list.
I've move the scrollbars so they show an item. Do I need to click on the item as well ? If so, thats an extrsa step that isn't obvious. Can it be avoided?
is the item highlighted?

lbx.jpg


you need to select an item for the listbox to have a value.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 15:51
Joined
Oct 29, 2018
Messages
21,358
> If you are getting null for the value and -1 for the listindex you have not selected an item in the list.
I've move the scrollbars so they show an item. Do I need to click on the item as well ? If so, thats an extrsa step that isn't obvious. Can it be avoided?
Hi. Yes, to select an item from a Listbox, the user has to click on the item on the list.
 

kirkm

Registered User.
Local time
Tomorrow, 11:51
Joined
Oct 30, 2008
Messages
1,257
Hmmmm. The item is not highlighted as there's no dropdown list to choose from . The value appears in the control (looking like it's just a textbox) but there are scrollbars, well they're not really scrollbars in the traditional sense. They're an up/down arrow and as you click it the values change. One overwriting the other. Is this not the norm ? I'm using Office 2019. I didn't do anything to change any defaults. And it works quite well like that as a dropdown isn't essential... but reading the value is.
 

kirkm

Registered User.
Local time
Tomorrow, 11:51
Joined
Oct 30, 2008
Messages
1,257
Ah, on thinking more I have set a listbox height to 0.6cm to match some other controls. Is this preventing a drop down ?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:51
Joined
May 7, 2009
Messages
19,169
i there is no Highlight on the listbox, then nothing is selected therefore the its Value is Null (nothing).
 

Users who are viewing this thread

Top Bottom