Listbox default selection & status

Timtropolis

Registered User.
Local time
Yesterday, 19:33
Joined
Jun 17, 2004
Messages
84
Greetings all

I have a popup form which is used to provide data to a function.
On the form are two combo boxes.... these are used as criteria to populate a listbox. When the user enters data in the second of the two combo boxes, I do a requery of the listbox (from OnChange event). I also do a quick For/Next loop to force selection of all items in the Listbox.

Code:
    Dim i As Integer
    Dim Str As String
    
    DoCmd.Requery (Me!lst_ISIN)
    
    '*** Selects all items in list box ***
    For i = 0 To Forms!frm_Parameter_Info.lst_ISIN.ListCount - 1
        Forms!frm_Parameter_Info.lst_ISIN.Selected(i) = True
    Next i

This all works well and does what its supposed to do.

The problem I'm running into is this. When I go to refer to the values in the listbox (which are the values that will be passed to my function), I keep getting Null when I reference them. I've read on a couple threads here that when using a Multi-select listbox (mine is a "Simple"), that the values are always NULL unless you foreably go thru the list. I've done this with the following code in my function:

Code:
    Dim item As Variant
              Dim i as Integer
   
    For Each item In Forms!frm_Parameter_Info.lst_ISIN.ItemsSelected
    [COLOR="SeaGreen"]'For i = 0 To Forms!frm_Parameter_Info.lst_ISIN.ListCount - 1[/COLOR]
            [B]TradingCode = Forms!frm_Parameter_Info.lst_ISIN.Column(item)[/B]
            CurrentDb.Execute "DELETE * FROM Output_file"

As you can see above, i've tried two different combinations but regardless, when I get to the line where I try to set TradingCode, I get a Null value error.
When I do a check on the selection status using using the .Count method, it returns the number of records selected in the listbox, so it seems as tho the property is being set.

Now if I go to the listbox and manually select / deselect records, then this code works fine.

My question is there another method I should be using to set the default selection?

Any help would be greatly appreciated,
Tim
 
Last edited:
Here:
Code:
TradingCode = Forms!frm_Parameter_Info.lst_ISIN.ItemData(item)

Plus catch Nulls using the Nz() function or set the datatype of TradingCode to be of type Variant.
 
Not sure what this has to do with my question about default selection.

Anyone else?
 

Users who are viewing this thread

Back
Top Bottom