IF Statement and List Boxes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, I am having difficulty nesting my IF statements when using muliList boxes
(FDT, FCT) (code below) and am having to use seperate radio buttons
(Me.CType, Me.CType) to enable the code to recognise wether the liines should
be run or not. I know this is bad code and it also increases input boxes for
the user. What i want is that when a list has an item selected it it
recognises that and runs the code, if both are chosen then it runs the code
that includes the logical operator.I am using '97.

Also and this might solve my problem, is there a listcount that tells you
how many items have been selected rather than are in the full list?

Thanks in advance for your time and assistance.
Alex

If (Me.CType) <> -1 And (Me.DType) <> -1 Then
strSQL = Left(strSQL, Len(strSQL) - 1)
strWhere = " AND CT IN( "
For i = 0 To fCT.ListCount - 1
If fCT.Selected(i) Then
strWhere = strWhere & "'" & fCT.Column(0, i) & "', "
End If
Next i
strSQL = strSQL & Left(strWhere, Len(strWhere) - 2) & " )"
strWhere = " DT IN( "
For i = 0 To fDT.ListCount - 1
If fDT.Selected(i) Then
strWhere = strWhere & "'" & fDT.Column(0, i) & "', "
End If
Next i
strSQL = strSQL & " " & Me.TypeLogical & " " & Left(strWhere,
Len(strWhere) - 2) & " );"
End If


If (Me.CType) <> -1 And (Me.DType) = -1 Then
strSQL = Left(strSQL, Len(strSQL) - 1)
strWhere = " AND CT IN( "
For i = 0 To fCT.ListCount - 1
If fCT.Selected(i) Then
strWhere = strWhere & "'" & fCT.Column(0, i) & "', "
End If
Next i
strSQL = strSQL & Left(strWhere, Len(strWhere) - 2) & " )"

End If


If (Me.DType) <> -1 And (Me.CType) = -1 Then
strSQL = Left(strSQL, Len(strSQL) - 1)
strWhere = " AND DT IN( "
For i = 0 To fDT.ListCount - 1
If fDT.Selected(i) Then
strWhere = strWhere & "'" & fDT.Column(0, i) & "', "
End If
Next i
strSQL = strSQL & Left(strWhere, Len(strWhere) - 2) & " )"

End If
 
You can tell how many items are selected with
Me.fCT.ItemsSelected.Count

As to your code issue, there is a good example of looping through the
selected items in a list box in VBA Help ItemsSelected topic.
 
Simple when you know how;), didn't realise you could use third dots, as for
the code i can sort that myself now.

Thanks Klatuu

Alex
 
Back
Top