Benginner2212
Member
- Local time
- Today, 01:21
- Joined
- Apr 6, 2023
- Messages
- 52
In my database, I have a form titled frmEquipTrack that has a calculated field titled txtMainDueDate that is supposed to be the date that a piece of equipment is supposed to be serviced by. When I I am trying to filter the forms by the date in the txtMainDueDate field so that I only get records where the date in the txtMainDueDate is in the current month. So far this is the code that I have:
When I run the code, I get a data mismatch error. I am not sure what I am doing wrong. Is it possible to filter forms based on a calculated field? Should this be a filter that is in the On Load Event of the frmEquipTrack?
Code:
Private Sub btnOpenMonthlyMaint_Click()
Dim frmDateCriteria
Dim fDate As Date
Dim lDate As Date
fDate = DateSerial(Year(Date), Month(Date), 1)
lDate = DateSerial(Year(Date), Month(Date) + 1, 0)
frmDateCriteria = "txtMaintDueDate between #" & fDate & "# AND #" & lDate & "#"
Debug.Print "fDate "; fDate
Debug.Print "lDate "; lDate
Debug.Print "frmDateCriteria "; frmDateCriteria
DoCmd.OpenForm "frmEquipTrack", acNormal, , frmDateCriteria, acWindowNormal, "MonthlyPM"
End Sub
When I run the code, I get a data mismatch error. I am not sure what I am doing wrong. Is it possible to filter forms based on a calculated field? Should this be a filter that is in the On Load Event of the frmEquipTrack?