I have a fairly simple query feeding a TransferSpreadsheet action. The query receives a couple of parameters from a couple of unbound text boxes on a form which in turn are filled from a couple of listboxes.
Listbox A (Report Groups) limits values displayed in listbox B (Positions). Listbox A selection is copied (OnClick) to Textbox A which is referenced as a criterion for a field in the underlying query...i.e. [Forms]![SelectionForm]![Textbox A]. Works great.
Listbox B and Textbox B are use the same approach except that Listbox B is multiselect. If I select only one value the process works fine. If I select more than one, the query does not return any records.
I have checked this prior to the TransferSpreadsheet action so I know the problem is in the query syntax itself.
I can copy and paste the actual result of the multiselect selection from its respective unbound text box and paste it into the query design grid criterion and it runs as expected but if I let the query run using the text box reference it doesn't. I have tried many variations in building the synatx as you will see in the commented lines in my code example below...Or...Like .. Or Like .. with quotes (chr(34)..without, etc
I have been going around in circles on this for hours and have read all FAQ's and many threads but cannot seem to see where the trouble is. My code for the On Click is as follows :
Private Sub Positions_In_ReportingGroups_Click()
Dim varItem As Variant
Dim strList As String
Dim nextItem As String
Dim ShowList As String
Me.Clear_btn.Visible = True
Me.txtSelected = Nothing
Me.SelectedReport = "ReportingGroups With Positions"
With Me.Positions_In_ReportingGroups
If .MultiSelect = 0 Then
Me.txtSelected = .Value
Me.txtParms = .Value
Else
strList = ""
ShowList = ""
For Each varItem In .ItemsSelected
ShowList = ShowList & .Column(0, varItem) & Chr(13) & Chr(10)
strList = strList & .Column(0, varItem) & " OR " ' -4
'strList = strList & .Column(0, varItem) & ", " ' for use with In()
'strList = strList & .Column(0, varItem) & " OR Like " ' -9
'strList = strList & Chr(34) & .Column(0, varItem) & Chr(34) & " OR Like " ' -11
Next varItem
If Len(strList) Then
strList = Left$(strList, Len(strList) - 4) 'strip extra characters from end of string
End If
If Len(ShowList) Then
ShowList = Left$(ShowList, Len(ShowList) - 2) 'strip extra characters from end of string
End If
Me.txtSelected = ShowList
Me.txtParms = strList
End If
End With
End Sub
Any help will be appreciated.
Listbox A (Report Groups) limits values displayed in listbox B (Positions). Listbox A selection is copied (OnClick) to Textbox A which is referenced as a criterion for a field in the underlying query...i.e. [Forms]![SelectionForm]![Textbox A]. Works great.
Listbox B and Textbox B are use the same approach except that Listbox B is multiselect. If I select only one value the process works fine. If I select more than one, the query does not return any records.
I have checked this prior to the TransferSpreadsheet action so I know the problem is in the query syntax itself.
I can copy and paste the actual result of the multiselect selection from its respective unbound text box and paste it into the query design grid criterion and it runs as expected but if I let the query run using the text box reference it doesn't. I have tried many variations in building the synatx as you will see in the commented lines in my code example below...Or...Like .. Or Like .. with quotes (chr(34)..without, etc
I have been going around in circles on this for hours and have read all FAQ's and many threads but cannot seem to see where the trouble is. My code for the On Click is as follows :
Private Sub Positions_In_ReportingGroups_Click()
Dim varItem As Variant
Dim strList As String
Dim nextItem As String
Dim ShowList As String
Me.Clear_btn.Visible = True
Me.txtSelected = Nothing
Me.SelectedReport = "ReportingGroups With Positions"
With Me.Positions_In_ReportingGroups
If .MultiSelect = 0 Then
Me.txtSelected = .Value
Me.txtParms = .Value
Else
strList = ""
ShowList = ""
For Each varItem In .ItemsSelected
ShowList = ShowList & .Column(0, varItem) & Chr(13) & Chr(10)
strList = strList & .Column(0, varItem) & " OR " ' -4
'strList = strList & .Column(0, varItem) & ", " ' for use with In()
'strList = strList & .Column(0, varItem) & " OR Like " ' -9
'strList = strList & Chr(34) & .Column(0, varItem) & Chr(34) & " OR Like " ' -11
Next varItem
If Len(strList) Then
strList = Left$(strList, Len(strList) - 4) 'strip extra characters from end of string
End If
If Len(ShowList) Then
ShowList = Left$(ShowList, Len(ShowList) - 2) 'strip extra characters from end of string
End If
Me.txtSelected = ShowList
Me.txtParms = strList
End If
End With
End Sub
Any help will be appreciated.