using listbox criteria

kidrobot

Registered User.
Local time
Today, 15:50
Joined
Apr 16, 2007
Messages
409
I currently use this code to open a query based on listbox criteria.

Code:
Dim ctl As Control
Dim varItm As Variant
Dim stItem As String
Dim strString As String
Dim qdfTemp As QueryDef

Set ctl = Me!lstT

    For i = 0 To lstT.ListCount - 1
        If lstTrains.Selected(i) Then
            If lstT.Column(0, i) = "All" Then
                flgSelectAll = True
            End If
            strIN = strIN & "'" & lstT.Column(0, i) & "',"
        End If
    Next i

Set qdfTemp = CurrentDb.CreateQueryDef("zzTempTable", "SELECT * FROM zz WHERE TT in (" & strIN & ");")

DoCmd.OpenQuery "zzTempTable"
DoCmd.OpenQuery "zz2final"
'Or alternatively output a report that references the query

'Delete query and free memory
CurrentDb.QueryDefs.Delete "qryTestQuery"
Set qdfTemp = Nothing

currently I am opening this query with a new temp query "zzTempTable", is there anyway I can use this code to just open my zz table with the appropriate listbox criteria?
 
Is this program for Norfolk Southern?

Just set the report data to the SQL info.

Report.Recordset = "SELECT * FROM zz WHERE TT in (" & strIN & ");"
 
Last edited:
I would build a wherecondition for either OpenForm or OpenReport.
 
Is this program for Norfolk Southern?

Just set the report data to the SQL info.

Report.Recordset = "SELECT * FROM zz WHERE TT in (" & strIN & ");"

Yes, how could you tell?
 
Used to intern for them in Norfolk. Was looking for a job there, but not really anymore. This is off-topic though, did the new recordset work?
 
Last edited:

Users who are viewing this thread

Back
Top Bottom