D
David McDonald
I am using a listbox with multiple selections enabled. I
have created a function that successfully returns the
value of a variable that is loaded from the selections in
the listbox.
I use this function as selection criteria in a query.
Problem is that multiple selections return Null results
in the query; although single selection returns correct
data, and no selections returns all records (which is
correct).
If I cut and paste the result of the function from the
immediate window into the query, the query works fine.
For some reason, when the function is in the query and
multiple selections are made, it does not work!
I have tried variation with adding Chr(34) (double
quotes) as well as single quotes. The word 'Or' gets
inserted, it looks good, it just doesnt work.
HELP PLEASE - Code below:
Public SeriesSelected As String
Private Sub List8_LostFocus()
Dim ctlSource As Object
Dim IntCurrentRow As Integer
Set ctlSource = Forms!Frm_Testing!List8
SeriesSelected = ""
For IntCurrentRow = 0 To ctlSource.ListCount - 1
If ctlSource.Selected(IntCurrentRow) Then
'SeriesSelected = SeriesSelected & Chr(39) & Trim
(Str(ctlSource.Column(0, IntCurrentRow))) & Chr(39) & "
Or "
'SeriesSelected = SeriesSelected & Chr(34) & Trim
(Str(ctlSource.Column(0, IntCurrentRow))) & Chr(34) & "
Or "
SeriesSelected = SeriesSelected & Trim(Str
(ctlSource.Column(0, IntCurrentRow))) & " Or "
'SeriesSelected = "'" & SeriesSelected &
ctlSource.Column(0, IntCurrentRow) & "'" & " Or "
End If
Next IntCurrentRow
If Len(SeriesSelected) > 4 Then
SeriesSelected = Left(SeriesSelected, Len
(SeriesSelected) - 4)
'SeriesSelected = "Like " & SeriesSelected
Else
'SeriesSelected = Chr(34) & "*" & Chr(34)
'SeriesSelected = "Like " & Chr(34) & "*" & Chr(34)
SeriesSelected = "*"
End If
Public Function Return_SeriesSelected()
If SeriesSelected = "" Then
Return_SeriesSelected = "*"
Else
Return_SeriesSelected = SeriesSelected
End If
End Function
have created a function that successfully returns the
value of a variable that is loaded from the selections in
the listbox.
I use this function as selection criteria in a query.
Problem is that multiple selections return Null results
in the query; although single selection returns correct
data, and no selections returns all records (which is
correct).
If I cut and paste the result of the function from the
immediate window into the query, the query works fine.
For some reason, when the function is in the query and
multiple selections are made, it does not work!
I have tried variation with adding Chr(34) (double
quotes) as well as single quotes. The word 'Or' gets
inserted, it looks good, it just doesnt work.
HELP PLEASE - Code below:
Public SeriesSelected As String
Private Sub List8_LostFocus()
Dim ctlSource As Object
Dim IntCurrentRow As Integer
Set ctlSource = Forms!Frm_Testing!List8
SeriesSelected = ""
For IntCurrentRow = 0 To ctlSource.ListCount - 1
If ctlSource.Selected(IntCurrentRow) Then
'SeriesSelected = SeriesSelected & Chr(39) & Trim
(Str(ctlSource.Column(0, IntCurrentRow))) & Chr(39) & "
Or "
'SeriesSelected = SeriesSelected & Chr(34) & Trim
(Str(ctlSource.Column(0, IntCurrentRow))) & Chr(34) & "
Or "
SeriesSelected = SeriesSelected & Trim(Str
(ctlSource.Column(0, IntCurrentRow))) & " Or "
'SeriesSelected = "'" & SeriesSelected &
ctlSource.Column(0, IntCurrentRow) & "'" & " Or "
End If
Next IntCurrentRow
If Len(SeriesSelected) > 4 Then
SeriesSelected = Left(SeriesSelected, Len
(SeriesSelected) - 4)
'SeriesSelected = "Like " & SeriesSelected
Else
'SeriesSelected = Chr(34) & "*" & Chr(34)
'SeriesSelected = "Like " & Chr(34) & "*" & Chr(34)
SeriesSelected = "*"
End If
Public Function Return_SeriesSelected()
If SeriesSelected = "" Then
Return_SeriesSelected = "*"
Else
Return_SeriesSelected = SeriesSelected
End If
End Function