Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query based on Values Selected in List Box

Status
Not open for further replies.
Oct 23, 2007
36
US
I have a list Box in Form1 of all SalesReps, it is set to Multi-Select and I want to be able to pull the values that are selected in a Query(Can be one or Multi Reps selected). I have tried =[Forms]![Form1]![ListBox1] in the query and that doesn't work. Does anyone know how to do this?

Thanks,
 
What do you mean "that didn't work"? Did it do nothing, return what you didn't expect or give an error message. If your expression was in the the critera section in the query try removing the equals sign.
 
It didn't give me an error, the query ran but nothing showed up in the query.
 
Try this, adapted from help file,
Code:
    Dim ctlSource As Control
    Dim strCrit As String
    Dim intCurrentRow As Integer
    
    Set ctlSource = frm!lstSource
    
    For intCurrentRow = 0 To ctlSource.ListCount - 1
        If ctlSource.Selected(intCurrentRow) Then
            strCrit = strCrit & ctlSource.Column(0, _
                 intCurrentRow) & " OR "
        End If
    Next intCurrentRow
    
    'trim last " OR "
    if nz(strCrit,"")<>"" then strCrit=left(strCrit,len(strCrit)-4)

    'put or criteria in a text control
    frm!txtCrit=strCrit

Now run your query but set the criteria to be frm!txtCrit...

JB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top