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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 list boxes used as creteria

Status
Not open for further replies.

Ragah21

MIS
Apr 17, 2007
17
US
I have 2 list boxes that I need to use as my creteria to run a report from a
query.
The code below worked for the first list box, how can I add the second as
part of my cretieria?
Note, the first list box contain NAME, and the second list box contain STATUS
Thanks

Private Sub Command11_Click()
Dim LBx As ListBox, Cri As String, DQ As String, itm

Set LBx = Me!List2
DQ = """"

If LBx.ItemsSelected.Count > 0 Then
For Each itm In LBx.ItemsSelected
If Cri <> "" Then
Cri = Cri & ", " & DQ & LBx.Column(1, itm) & DQ
Else
Cri = DQ & LBx.Column(1, itm) & DQ
End If
Next

Cri = "[NAME] In(" & Cri & ")"
Debug.Print Cri
End If

DoCmd.OpenReport "Step1_Member_Status", acViewPreview, , Cri
Set LBx = Nothing

End Sub
 
Code:
Private Sub Command11_Click()
Dim LBx As ListBox, criName As String, criStatus As String, Cri As String, DQ As String, itm
DQ = """"
Set LBx = Me!List2
 
   
   If LBx.ItemsSelected.Count > 0 Then
      For Each itm In LBx.ItemsSelected
         If criName <> "" Then
            criName = criName & ", " & DQ & LBx.Column(1, itm) & DQ
         Else
            criName = DQ & LBx.Column(1, itm) & DQ
         End If
      Next
      
      criName = "[NAME] In(" & criName & ")"
      Debug.Print criName
   End If
Set LBx = Me!Listxxx
 
   
   If LBx.ItemsSelected.Count > 0 Then
      For Each itm In LBx.ItemsSelected
         If criStatus <> "" Then
            criStatus = criStatus & ", " & DQ & LBx.Column(1, itm) & DQ
         Else
            criStatus = DQ & LBx.Column(1, itm) & DQ
         End If
      Next
      
      criStatus = "[Status] In(" & criStatus & ")"
      Debug.Print criStatus
   End If
Cri = criName & iff(criName > "", " and ", "") & criStatus
DoCmd.OpenReport "Step1_Member_Status", acViewPreview, , Cri
Set LBx = Nothing
    
End Sub
 
For some reason it returns nothing? But it seems to work.

Cri = criName & iff(criName > "", " and ", "") & criStatus

Is it IIF or IFF.
Even when I change it return nothing
 
Cri = criName & IIf(criName > "", " and ", "") & criStatus

I want both conditions to be true? its working for one or the other.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top