Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select case using loop 1

Status
Not open for further replies.

Richey

Technical User
Aug 29, 2000
121
GB
Hi

i've got the following code. I won't know how mnay items will be in List0, because it gets added to frequently. therefore i can never say how many cases I require (in the example below i have used 5) but it might be 12, it might be 14 etc. How can i match the number of case statements to the number of items in the List Box. the items are held within tblKeyStrats.

thanks
rich

Code:
Dim strStrat As String
Select Case Me.List0.Value

Case 1
strStrat = "=1"
Case 2
strStrat = "=2"
Case 3
strStrat = "=3"
Case 4
strStrat = "=4"
Case 5
strStrat = "=5"
Case Else
strStrat = ">0"

End Select
strFilter = "[RiskStrat] " & strStrat
 
Have a look at the ListCount property of the ListBox object.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
ok thanks
so lets assume it returns 10, then how do i add 10 case statements programatically ?

thanks
 
Something like this ?
strStrat = ">0"
For i = 1 To Me.List0.ListCount
If i = Me.List0.Value Then
strStrat = "=" & i
Exit For
End If
Next

Or this ?
If Me.List0.Value > 0 And Me.List0.Value <= Me.List0.ListCount Then
strStrat = "=" & Me.List0.Value
Else
strStrat = ">0"
End If

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top