Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Filter data between two dates is crucial in data analysis. It enables businesses to identify trends, track performance, and make informed decisions. This skill is vital for leveraging the full potential of data-driven decision-making.
Click to Subscribe
Watch the Video tutorial
We will use the [Hire Date] column in the Employees’ data as a reference to the date column.
VBA Code Method: A single-date filter criterion is a simple and easy approach with a textbox and a button.
Apply this code to the “On Click” event of the button.
Private Sub CmdSearch7_Click()
Dim strGenderFind As String
'Criteria
strGenderFind = "[Hire Date] = #" & Me.Search7 & "#"
Me.Form.Filter = strGenderFind
Me.Form.FilterOn = True
End Sub
Table Query Method: Build a query with all the necessary fields from the table and apply the Date Text box reference into the criteria of [Hire Date] field.
The button will only act to refresh the form. To clear the filter from the form, you have to empty the date textbox or a better approach is to create another button to clear the form which will be used to make the text box null and refresh the form.
VBA Code Method: Create 2 text boxes and a button in the head section of your form and name them properly.
Apply this code to the “On Click” event of the button.
Private Sub CmdBetweenDt_Click()
Dim strGenderFind As String
'Criteria
strGenderFind = "[Hire Date] between #" & Me.txtDtFrom & "# and #" & Me.txtDtTo & "#"
Me.Form.Filter = strGenderFind
Me.Form.FilterOn = True
End Sub
Table Query Method: Build a query with all the necessary fields from the table and apply the Date Text box references into the criteria of [Hire Date] field like this:
Between FormTxtDateFrom And FormTxtDateTo
In the above expression, both text boxes are the references of the date text boxes.
The button will only act to refresh the form. To clear the filter from the form, you have to empty the date textbox or a better approach is to create another button to clear the form which will be used to make the text box null and refresh the form.
The Between Two Dates Filter Criteria doesn’t work because Criteria does not include time.
The criteria is based on two dates input. You might not applied the date format.