So I am making a defects database in MS Access for work and I am working on a search form to find a specific employees defects between specific dates. I already have the date range search working with a button, but I haven't figured out how to add my EmployeeNameBox into the filter results. This is what I have.
Private Sub Searchbtn_Click()
Me.Filter = "[DayMonthYear] BETWEEN #" & Me.Date1Filt & "# AND #" & Me.Date2Filt & "#"
Me.FilterOn = True
End Sub
Works great for the date range I want, but I need to add in the employee name as well. Any help would be much appreciated.
Assuming that your EmployeeNameBox
will always be populated when searching, you just need to add it to your filter. I've found it's easier to store your filter in a variable, then assign it to Me.Filter
at the end. So something like:
Private Sub Searchbtn_Click()
Dim sFilter as String
sFilter = _
"[DayMonthYear] BETWEEN " & _
"#" & Me.Date1Filt & "# AND " & _
"#" & Me.Date2Filt & "# " & _
" AND [EmployeeName] = """ & Me.EmployeeNameBox & """"
Me.Filter = sFilter
Me.FilterOn = True
End Sub