|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hello,
I am trying to use a multiple selection in a list box as criteria of a query. From what I have found on the web so far this can not be done. Does anyone know if it can and if so how? If not I was thinking of adding the selections that the user picks into a table and use join to pull the correct data. Does this sound like the correct way? Any help with this would be much appreciated. Thanks!!!! |
|
#2
|
|||
|
|||
|
Try using the following code in the AfterUpdate event for your list box. Substitute the items in Bold with the correct names of your query, table, field name and control.
Private Sub MultiListBox_AfterUpdate() On Error GoTo Err_Handler Dim db As DAO.Database Dim qdf As DAO.QueryDef Dim varItem As Variant Dim strCriteria As String Dim strSQL As String Set db = CurrentDb() Set qdf = db.QueryDefs("QueryName") For Each varItem In Me!MultiListBox.ItemsSelected strCriteria = strCriteria & "TableName.FieldName = " & Chr(34) _ & Me!MultiListBox.ItemData(varItem) & Chr(34) & "OR " Next varItem strCriteria = Left(strCriteria, Len(strCriteria) - 3) strSQL = "SELECT * FROM TableName " & _ "WHERE " & strCriteria & ";" qdf.SQL = strSQL DoCmd.OpenQuery "QueryName" Set db = Nothing Set qdf = Nothing Exit_Handler: Exit Sub Err_Handler: MsgBox Err.Number & " " & Err.Description Resume Exit_Handler End Sub This will open the query with the items from your list box as the filter criteria. lwells |
|
#3
|
|||
|
|||
|
Worked great. Thanks!!!!!
|
![]() |
| Viewing: Dev Articles Community Forums > Databases > Microsoft Access Development > Multi select list box |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|