kieriosity
IS-IT--Management
I have the following bit of code placed in a module:
Function selectCriteria(ctl)
'Flush out the Criteria variable before adding new data
Criteria = ""
'Loop through the list box and build a string
'for all items selected
For Each Itm In ctl.ItemsSelected
If Len(Criteria) = 0 Then
Criteria = Chr(34) & ctl.ItemData(Itm) & Chr(34)
Else
Criteria = Criteria & "," & Chr(34) & ctl.ItemData(Itm) _
& Chr(34)
End If
Next Itm
'If no items are selected in the list box then show a message
'box telling the user they need to select an item.
If Len(Criteria) = 0 Then
Itm = MsgBox("You must select one or more items in the" & _
" list box!", 0, "No Selection Made"
Exit Function
End If
End Function
I'm calling the function from a form with a list box.
Set ctl = Me![DisciplineList]
Call basSelectCriteria.selectCriteria(ctl)
I can't get it to return a value to the form. I can if the function is in the same form and not in a module, but I have several forms that need to use this function. I need to put the value in the criteria variable so I can use it to build an SQL query. Any ideas? Thanks.
Function selectCriteria(ctl)
'Flush out the Criteria variable before adding new data
Criteria = ""
'Loop through the list box and build a string
'for all items selected
For Each Itm In ctl.ItemsSelected
If Len(Criteria) = 0 Then
Criteria = Chr(34) & ctl.ItemData(Itm) & Chr(34)
Else
Criteria = Criteria & "," & Chr(34) & ctl.ItemData(Itm) _
& Chr(34)
End If
Next Itm
'If no items are selected in the list box then show a message
'box telling the user they need to select an item.
If Len(Criteria) = 0 Then
Itm = MsgBox("You must select one or more items in the" & _
" list box!", 0, "No Selection Made"
Exit Function
End If
End Function
I'm calling the function from a form with a list box.
Set ctl = Me![DisciplineList]
Call basSelectCriteria.selectCriteria(ctl)
I can't get it to return a value to the form. I can if the function is in the same form and not in a module, but I have several forms that need to use this function. I need to put the value in the criteria variable so I can use it to build an SQL query. Any ideas? Thanks.