A
angie
i have the following code for my multiselect listbox:
Private Sub VEHICLE_AfterUpdate()
Dim qdfCurr As DAO.QueryDef
Dim strSelected As String
Dim strSQL As String
Dim varSelected As Variant
If Me.VEHICLE.ItemsSelected.Count = 0 Then
' Nothing selected in the listbox: nothing needs to be done
Else
' Loop through all of the selected rows, adding their value to strSelected
' as a comma-separated list
For Each varSelected In Me.VEHICLE.ItemsSelected
strSelected = strSelected & """" & Me.VEHICLE.ItemData(varSelected) &
""", "
Next varSelected
' Remove the extra ", " from the end of strSelected
strSelected = Left(strSelected, Len(strSelected) - 2)
' Build the revised SQL for your query
strSQL = "SELECT itemcode,family " & _
"FROM [APPLICATIONS-TBL] " & _
"WHERE family IN (" & strSelected & ")"
' Update the query to use the new SQL
Set qdfCurr = CurrentDb().QueryDefs("APPLICATIONS")
qdfCurr.SQL = strSQL
qdfCurr.CLOSE
End If
End Sub
i want to replace the "Nothing selected in the listbox: nothing needs to be
done" with "return all the records". how do i have to put it in the code
correctly?
Private Sub VEHICLE_AfterUpdate()
Dim qdfCurr As DAO.QueryDef
Dim strSelected As String
Dim strSQL As String
Dim varSelected As Variant
If Me.VEHICLE.ItemsSelected.Count = 0 Then
' Nothing selected in the listbox: nothing needs to be done
Else
' Loop through all of the selected rows, adding their value to strSelected
' as a comma-separated list
For Each varSelected In Me.VEHICLE.ItemsSelected
strSelected = strSelected & """" & Me.VEHICLE.ItemData(varSelected) &
""", "
Next varSelected
' Remove the extra ", " from the end of strSelected
strSelected = Left(strSelected, Len(strSelected) - 2)
' Build the revised SQL for your query
strSQL = "SELECT itemcode,family " & _
"FROM [APPLICATIONS-TBL] " & _
"WHERE family IN (" & strSelected & ")"
' Update the query to use the new SQL
Set qdfCurr = CurrentDb().QueryDefs("APPLICATIONS")
qdfCurr.SQL = strSQL
qdfCurr.CLOSE
End If
End Sub
i want to replace the "Nothing selected in the listbox: nothing needs to be
done" with "return all the records". how do i have to put it in the code
correctly?