T
Tarnia
I have 3 combo boxes: dayofmonth, month, year in addition to common fields
(name, lessontype, instructor, payment). I would like the user to be able to
select a day,month and year and the form to be filtered by date such that
only data recorded for that date is shown. However, I am having trouble. My
code is given below; any help would be appreciated
Private Sub Go_payment_Click()
'declare variables
Dim datefilter As String
Dim vardayofmonth, varmonth, varyear, vardate As String
Dim frm As Form
'lookup value for day of month in form
vardayofmonth = DLookup("[day of month]", "payments", "[day of month]='"
&
Forms!payments![day of month] & "'") payments and store as dayofmonth
'lookup value for month in form
varmonth = DLookup("[month]", "payments", "[month]='" &
Forms!payments!month & "'")
'lookup value for year in form payments and store as year
varyear = DLookup("[year]", "payments", "[year]='" & Forms!payments!year
& "'")
'concatenate day, month and year into a date: "vardate"
vardate = CDate(vardayofmonth & "-" & varmonth & "-" & varyear)
' set criteria for filter
datefilter = BuildCriteria("Date", dbDate, vardate)
' open form to be filtered
DoCmd.OpenForm "viewpaymentsmadetoday" 'open form
Set frm = Forms!viewpaymentsmadetoday 'Return Form object variable set
to "viewpaymentsmadetoday".
'filter form
frm.Filter = datefilter
FilterOn = True 'allow filters
End Sub
(name, lessontype, instructor, payment). I would like the user to be able to
select a day,month and year and the form to be filtered by date such that
only data recorded for that date is shown. However, I am having trouble. My
code is given below; any help would be appreciated
Private Sub Go_payment_Click()
'declare variables
Dim datefilter As String
Dim vardayofmonth, varmonth, varyear, vardate As String
Dim frm As Form
'lookup value for day of month in form
vardayofmonth = DLookup("[day of month]", "payments", "[day of month]='"
&
Forms!payments![day of month] & "'") payments and store as dayofmonth
'lookup value for month in form
varmonth = DLookup("[month]", "payments", "[month]='" &
Forms!payments!month & "'")
'lookup value for year in form payments and store as year
varyear = DLookup("[year]", "payments", "[year]='" & Forms!payments!year
& "'")
'concatenate day, month and year into a date: "vardate"
vardate = CDate(vardayofmonth & "-" & varmonth & "-" & varyear)
' set criteria for filter
datefilter = BuildCriteria("Date", dbDate, vardate)
' open form to be filtered
DoCmd.OpenForm "viewpaymentsmadetoday" 'open form
Set frm = Forms!viewpaymentsmadetoday 'Return Form object variable set
to "viewpaymentsmadetoday".
'filter form
frm.Filter = datefilter
FilterOn = True 'allow filters
End Sub