Building search/filter criteria

S

Samnang Sao

I am designing a form where I can search the disbursement info by
selecting 1 or more payment stages and 1 or more fund source. From
what the user select, build the where clause and pass it as a record
source to a subform. I have 2 listboxes, 1 button for Search and 1 sub
form for display result. My problem is how can I combine the two
listboxes in one where clause

'Listbox 1
Private Sub ListboxPaymentStage_Click()
Dim varItem As Variant
Dim Stg As String

Stg = "IN ('"
For Each varItem In Me.Combo0.ItemsSelected
Stg = Stg & Me.ListboxPaymentStage.ItemData(varItem) & "', '"
Next varItem

ZZ_Stages = Mid(Stg, 1, Len(Stg) - 4) & "')"

End Sub

'Listbox 2

Private Sub lstFundSource_Click()
Dim varItem As Variant
Dim Stg As String

Stg = "IN ('"

For Each varItem In Me.lstFundSource.ItemsSelected
Stg = Stg & Me.lstFundSource.ItemData(varItem) & "', '"
Next varItem

ZZ_Fund_SOurce = Mid(Stg, 1, Len(Stg) - 4) & "')"
End Sub


On my search button I had the code below

Private Sub Command8_Click()
Dim frmSQL As String
Dim St As String
Dim qrySTG As String

If Not IsNull(ZZ_Stages) Then
St = " WHERE (((frmCofundTable.Stages) " & ZZ_Stages & "));"
End If

If IsNull(ZZ_Fund_SOurce) Then
qrySTG = Null
Else
qrySTG = " WHERE )"
End If

frmSQL = "SELECT frmCofundTable.* FROM frmCofundTable " & St ''&
qrySTG
Forms![Main]![SubForm].Form.RecordSource = frmSQL
Me.SubForm.Requery

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top