Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String
Dim strSQLWhere As String
Dim varItem As Variant
On Error GoTo ErrHandler
strSQLWhere = vbNullString
'***************************************************
'* Loop thru list box to build your Where clause *
'***************************************************
If (Lst.ItemsSelected.Count > 0) Then
strSQLWhere = " Where "
For Each varItem In Lst.ItemsSelected
strSQLWhere = strSQLWhere & "YourFieldName=" & Lst.Column(0, varItem) & " OR "
Next varItem
strSQLWhere = Left(strSQLWhere, Len(strSQLWhere) - 4) 'get rid of last or
End If
strSQL = "Select * Form YourTable " & strSQLWhere
'************************************************
'* Delete original query and create a new one *
'************************************************
Set dbs = CurrentDb
dbs.QueryDefs.Delete "qryNameOfYourQuery"
Set qdf = dbs.CreateQueryDef("qryNameOfYourQuery", strSQL)
strSQL = vbNullString
DoEvents
ExitProcedure:
Exit Sub
ErrHandler:
If (Err.Number = 3265) Then 'IFT, tryed to delete a query that did not exist
Resume Next
Else
MsgBox Err.Number & Err.Description
Resume ExitProcedure
End If