I found this and think it is likely the method to run a query through a multi select combo box on a form and would like to know how to get it to expoert out with the docmd transferspreadsheet.
Private Sub cmdPrintLabels_Click()
Dim strSelected As String
Dim strWhere As String
Dim varSelected As Variant
If Len(Me!Textbox1 & vbNullString) = 0 Then
MsgBox "You must put something in Textbox 1"
Exit Sub
Else
strWhere = strWhere & "Field1 = '" & Me!Textbox1 & "' AND "
End If
If Len(Me!Textbox2 & vbNullString) > 0 Then
strWhere = strWhere & "Field2 = '" & Me!Textbox2 & "' AND "
End If
If Me!MyListbox.ItemsSelected.Count > 0 Then
For Each varSelected In Me!MyListbox.ItemsSelected
strSelected = strSelected & Me!MyListbox.ItemData(varSelected) & ", "
Next varSelected
strSelected = Left$(strSelected, Len(strSelected) - 2)
strWhere = strWhere & "Field3 In (" & strSelected & ") AND "
End If
' Remove the extraneous " AND " from the end of strWhere
strWhere = Left$(strWhere, Len(strWhere) - 5)
DoCmd.OpenReport "MyReport", acViewPreview, , strWhere
End Sub
Private Sub cmdPrintLabels_Click()
Dim strSelected As String
Dim strWhere As String
Dim varSelected As Variant
If Len(Me!Textbox1 & vbNullString) = 0 Then
MsgBox "You must put something in Textbox 1"
Exit Sub
Else
strWhere = strWhere & "Field1 = '" & Me!Textbox1 & "' AND "
End If
If Len(Me!Textbox2 & vbNullString) > 0 Then
strWhere = strWhere & "Field2 = '" & Me!Textbox2 & "' AND "
End If
If Me!MyListbox.ItemsSelected.Count > 0 Then
For Each varSelected In Me!MyListbox.ItemsSelected
strSelected = strSelected & Me!MyListbox.ItemData(varSelected) & ", "
Next varSelected
strSelected = Left$(strSelected, Len(strSelected) - 2)
strWhere = strWhere & "Field3 In (" & strSelected & ") AND "
End If
' Remove the extraneous " AND " from the end of strWhere
strWhere = Left$(strWhere, Len(strWhere) - 5)
DoCmd.OpenReport "MyReport", acViewPreview, , strWhere
End Sub