M
Mr. Bud
Hi and TIA. I have a procedure that constructs an In statement and stores
that value in a module level variable. I then want to use criteria in my
query to call the function to pull the value stored in the variable. I know
that data being stored is constructed as required but when I run the query
with the criteria to GetUIC() no records are returned. I have a control on
my form that calls the GetUIC() function and displays the string that was
built from my multi-select listbox. If I cut and paste that string as the
criteria for my query the correct records are returned. Procedure below
creates the string. The field is a text field. Any ideas are appreciated.
Private Function BuildWhereCondition(strControl As String) As String
'Set up the WhereCondition Argument for the reports
Dim varItem As Variant
Dim strWhere As String
Dim ctl As Control
Dim strControl As String
strControl = "lstUIC"
Set ctl = Me.Controls(strControl)
Select Case ctl.ItemsSelected.Count
Case 0 'Include All
strWhere = ""
Case 1 'Only One Selected
strWhere = "= '" & _
ctl.ItemData(ctl.ItemsSelected(0)) & "'"
Case Else 'Multiple Selection
strWhere = "IN ("
With ctl
For Each varItem In .ItemsSelected
strWhere = strWhere & "'" & .ItemData(varItem) & "', "
Next varItem
End With
strWhere = Left(strWhere, Len(strWhere) - 2) & ")"
End Select
SetUIC (strWhere) 'Store value to module level variable
Me.Recalc
Debug.Print strWhere
End Function
Debug window returns = IN ('68971', '22202', '21533') and if I place this as
the criteria the records are returned. Thanks for your time.
that value in a module level variable. I then want to use criteria in my
query to call the function to pull the value stored in the variable. I know
that data being stored is constructed as required but when I run the query
with the criteria to GetUIC() no records are returned. I have a control on
my form that calls the GetUIC() function and displays the string that was
built from my multi-select listbox. If I cut and paste that string as the
criteria for my query the correct records are returned. Procedure below
creates the string. The field is a text field. Any ideas are appreciated.
Private Function BuildWhereCondition(strControl As String) As String
'Set up the WhereCondition Argument for the reports
Dim varItem As Variant
Dim strWhere As String
Dim ctl As Control
Dim strControl As String
strControl = "lstUIC"
Set ctl = Me.Controls(strControl)
Select Case ctl.ItemsSelected.Count
Case 0 'Include All
strWhere = ""
Case 1 'Only One Selected
strWhere = "= '" & _
ctl.ItemData(ctl.ItemsSelected(0)) & "'"
Case Else 'Multiple Selection
strWhere = "IN ("
With ctl
For Each varItem In .ItemsSelected
strWhere = strWhere & "'" & .ItemData(varItem) & "', "
Next varItem
End With
strWhere = Left(strWhere, Len(strWhere) - 2) & ")"
End Select
SetUIC (strWhere) 'Store value to module level variable
Me.Recalc
Debug.Print strWhere
End Function
Debug window returns = IN ('68971', '22202', '21533') and if I place this as
the criteria the records are returned. Thanks for your time.