Hello,
I posted this question earlier in the Queries Forum.
Because it's more a VBA subject and I still haven't got any answers, once again:
I've created a user defined function to get all the values which are selected from a
MultiSelect listbox.
The function returns a string containing all values.
The function itself works OK.
I try to refer to the function in an SQL statement in a WHERE clause:
SELECT somecolumns
FROM sometables
WHERE table1.ActivityNumber IN (ListBoxActivities());
being ListBoxActivities the function I would like to refer to.
After one or more items are selected in the listbox, the query is run by clicking on a button.
As result no rows are selected.
I guess the reason why no records are selected is in the function itself, returning a string as result.
I can't figure out how to solve this.
Here's the code used to create define the
function:
Option Compare Database
Option Explicit
Public strValuelist As String
Public Function ListBoxActivities() As String
Dim dbs As Database
Dim varItem As Variant
Dim lst As Listbox
Set lst= Forms![AutomaticRemittance]!Activities
Set dbs = CurrentDb
If lst.ItemsSelected.Count > 0 Then
With lst
For Each varItem In lst.ItemsSelected
strValuelist = strValuelist & "," & lst.ItemData(varItem)
Next varItem
End With
strValuelist = Mid(strValuelist, 2)
End If
Set dbs = Nothing
What's going wrong here?
RV
I posted this question earlier in the Queries Forum.
Because it's more a VBA subject and I still haven't got any answers, once again:
I've created a user defined function to get all the values which are selected from a
MultiSelect listbox.
The function returns a string containing all values.
The function itself works OK.
I try to refer to the function in an SQL statement in a WHERE clause:
SELECT somecolumns
FROM sometables
WHERE table1.ActivityNumber IN (ListBoxActivities());
being ListBoxActivities the function I would like to refer to.
After one or more items are selected in the listbox, the query is run by clicking on a button.
As result no rows are selected.
I guess the reason why no records are selected is in the function itself, returning a string as result.
I can't figure out how to solve this.
Here's the code used to create define the
function:
Option Compare Database
Option Explicit
Public strValuelist As String
Public Function ListBoxActivities() As String
Dim dbs As Database
Dim varItem As Variant
Dim lst As Listbox
Set lst= Forms![AutomaticRemittance]!Activities
Set dbs = CurrentDb
If lst.ItemsSelected.Count > 0 Then
With lst
For Each varItem In lst.ItemsSelected
strValuelist = strValuelist & "," & lst.ItemData(varItem)
Next varItem
End With
strValuelist = Mid(strValuelist, 2)
End If
Set dbs = Nothing
What's going wrong here?
RV