filter multiple fields

T

Tarnia

I would like to filter 3 fields at once from a combo box (day, month and
year). I can't simply make it one (the date) as there may be duplicate
values, so it makes the lookup list messy.

1) I have done this before for 1 field, but it doesn't work in this
particular form, (doesn't filter) despite using same code (outside of field
names)

2) how do I filter for multiple criteria? The help function hasn't given me
anything that will work

My code is below

Thanks

Private Sub Go_payment_Click()

Dim vardayofmonth, varmonth, varyear As String 'declare variables
Dim dayfilter, monthfilter, yearfilter As String
Dim frm As Form

vardayofmonth = DLookup("[dayofmonth]", "payments", "[dayofmonth]='" &
Forms!payments![dayofmonth] & "'") 'lookup value for day of month in form
payments and store as dayofmonth
varmonth = DLookup("[month]", "payments", "month='" &
Forms!payments!month & "'") 'lookup value for "month" in form payments and
store as month
varyear = DLookup("[year]", "payments", "[year]= '" &
Forms!payments!year & "'") 'lookup value for year in form payments and store
as year

dayfilter = BuildCriteria("[dayofmonth]", dbText, vardayofmonth)
monthfilter = BuildCriteria("month", dbText, varmonth)
yearfilter = BuildCriteria("year", dbText, varyear)

DoCmd.OpenForm "viewpaymentsmadetoday" 'open form
Set frm = Forms!viewpaymentsmadetoday 'Return Form object variable set
to "viewpaymentsmadetoday".

frm.Filter = dayfilter 'test if dayfilter is working

FilterOn = True 'allow filters
 

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

Similar Threads


Top