need the value of my list box

ghudson

Registered User.
Local time
Today, 12:24
Joined
Jun 8, 2002
Messages
6,194
How can I grab the value of my list box? I have a list box named lbVarianceTotals. I want to filter the record set based on the single selection of the list box using the DoubleClick event on the list box. When I run my code below, I am getting an invalid use of Null error. The value that is placed in the Filter properties is only the two single quotes. Account = '' What am I doing wrong?

Code:
Private Sub lbVarianceTotals_DblClick(Cancel As Integer)
On Error GoTo Err_lbVarianceTotals_DblClick
        
    Me.FilterOn = True
    DoCmd.ApplyFilter , "Account = " & "'" & lbVarianceTotals & "'"
    
Exit_lbVarianceTotals_DblClick:
    Exit Sub
    
Err_lbVarianceTotals_DblClick:
    MsgBox Err.Number & " - " & Err.Description
    Resume Exit_lbVarianceTotals_DblClick
    
End Sub
Thanks in advance for your help!
 
From Help:

When a list box control's MultiSelect property is set to None, only one item can have its Selected property set to True. When a list box control's MultiSelect property is set to Simple or Extended, any or all of the items can have their Selected property set to True. A multiple-selection list box bound to a field will always have a Value property equal to Null. You use the Selected property or the ItemsSelected collection to retrieve information about which items are selected.


Any guidance there?
 
I'm guessing either that a choice hasn't been made from the listbox or that your list box is multiselect. Is one of those the case?
 
Yes, my list box was set to Multi Select = Extended. Thanks for the tip for I found some code that actually works in the Access help files for the ItemsSelected Collection. Below is what I am using that will allow me to filter the selected number from the double click event of the list box...

Dim frm As Form, ctl As Control
Dim vItem As Variant

Set frm = Forms!fVariance
Set ctl = frm!lbVarianceTotals
For Each vItem In ctl.ItemsSelected
'Debug.Print ctl.ItemData(vItem)
'MsgBox "Account = " & "'" & ctl.ItemData(vItem) & "'"
DoCmd.ApplyFilter , "Account = " & "'" & ctl.ItemData(vItem) & "'"
Next vItem

Thanks again for your help dcx693 & AncientOne !!! :D
 

Users who are viewing this thread

Back
Top Bottom