This is embarrassing, I am having brain freeze...
I have collected a string of values in a sub.
I want to use that string in another sub, rather than using the same block of code again and again.
When I 'Call' it
I get an error "Compile Error: Expected Function or variable
If I try to add a variable and call it ...
I get the error. "Compile Error: Variable not defined"
If I try and define the variable and then call it
I get the "Compile Error: Variable not defined"
I know this is entry level stuff, I am just not able to work this one out.
Any help, most appreciated
I have collected a string of values in a sub.
Code:
Private Sub CollectString()
'Collect those selected in the list
Dim strSQL As String
Dim strwhere As String
Dim ctl As Control
Dim varItem As Variant
'make sure a selection has been made
If Me.ListOfValues.ItemsSelected.Count = 0 Then
Exit Sub
End If
'add selected values to string
Set ctl = Me.ListOfValues
For Each varItem In ctl.ItemsSelected
'Use this line if the value is text
'strWhere = strWhere & Chr(34) & ctl.ItemData(varItem) & Chr(34) & ","
'Use this line if your value is numeric
strwhere = strwhere & ctl.Column(5, varItem) & ","
Next varItem
'trim trailing comma
strwhere = Left(strwhere, Len(strwhere) - 1)
End Sub
I want to use that string in another sub, rather than using the same block of code again and again.
When I 'Call' it
Code:
Private Sub Command39_Click()
Call CollectString
Msgbox CollectString
End Sub
I get an error "Compile Error: Expected Function or variable
If I try to add a variable and call it ...
Code:
Private Sub Command39_Click()
Call CollectString(strWhere)
Msgbox strwhere
End Sub
I get the error. "Compile Error: Variable not defined"
If I try and define the variable and then call it
Code:
Private Sub Command39_Click()
Dim strValues
strValues = CollectString(strWhere)
MsgBox strValues
End Sub
I get the "Compile Error: Variable not defined"
I know this is entry level stuff, I am just not able to work this one out.
Any help, most appreciated