Listbox value

kirkm

Registered User.
Local time
Today, 23:10
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.
 
Are your listboxes multi select?
 
The listboxes show the expected values and change with their arrows.
list boxes dont have arrows. Are you talking about combo boxes?
 
No, that is I haven't set that property. Should be one item only.
 
> 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.
 
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.
 
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.
 
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
 
AddItem is for List RowSourceType only.
The RowSourceType needs to be Table/Query to use a Select.
 
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.
 
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
 
> 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.
 
> 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.
 
> 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?
 
> 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.
 
> 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.
 
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.
 
Ah, on thinking more I have set a listbox height to 0.6cm to match some other controls. Is this preventing a drop down ?
 
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

Back
Top Bottom