Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I want to be able to use different listbox controls with this function, but I
don't know how to set the name of the listbox so that it can be variable for the routine: The routine completly works if I were to replace LB (in the body) with the name of the listbox Here is my function : (I have placed ??? where I am unsure) Private Function BuildWhereCondition(LB As Listbox???) As String 'Set up the WhereCondition Argument for the reports Dim strWhere As String Dim lSelectedCount As Long Dim i As Variant 'The index of whatever they select set LB = ???? lSelectedCount = 0 'MsgBox "listcount -1 " & lb.ListCount - 1 For x = 0 To LB.ListCount - 1 If LB.Selected(x) = True Then lSelectedCount = lSelectedCount + 1 i = x End If Next x Select Case lSelectedCount Case 0 'Include All strWhere = "" Case 1 'Only One Selected strWhere = "= '" & LB.List(i) & "'" ' MsgBox strWhere Case Else 'Multiple Selection strWhere = " IN (" For x = 0 To LB.ListCount - 1 If LB.Selected(x) = True Then strWhere = strWhere & "'" & LB.List(x) & "', " End If Next x strWhere = Left(strWhere, Len(strWhere) - 2) & ")" End Select BuildWhereCondition = strWhere End Function |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Setting Listbox Size VBA | Excel Worksheet Functions | |||
Setting and filter Listbox data | Excel Discussion (Misc queries) | |||
Setting a VBA Control as a variable | Excel Programming | |||
Problems with setting values in a listbox | Excel Programming | |||
setting a range variable equal to the value of a string variable | Excel Programming |