I have made a search form that allows the user to search within company expense reports for certain clients, projects, employees, and date ranges.
For the Date Criteria Box I have the following formula:
Between [Forms]![Search Form]![txtDateFrom] And [Forms]![Search Form]![txtDateTo]
This works fine but if I don't input any dates then no records show up, I want to change this so that all records will show up if they are left blank.
I've been able to do this for the project, client, and employee fields with the following formulas:
Like "*" & [Forms]![Search Form]![cboProject] & "*"
Like "*" & [Forms]![Search Form]![cboClient] & "*"
Like "*" & [Forms]![Search Form]![txtEmployee] & "*"
You guys probably know exactly what this means but I'll briefly explain it anyways: when I enter something in the textbox for Employee, the combo box for Project, or the combo box for Client in my search for and run the query, only the values that match what I entered appear. The Like "*" bit makes it so that if nothing is entered all the values show up.
I want to do the same for the date range but it is a bit trickier for me to do, can anyone help me with the syntax of this to make my date from and date to boxes show everything if left empty? Because right now if i leave them empty no records are shown which is a huge problem for the user side.
I've tried:
Like "*" & (Between [Forms]![Search Form]![txtDateFrom] And [Forms]![Search Form]![txtDateTo]) & "*"
But it didn't work for me and when I would input date ranges the incorrect date ranges would appear in the query.
What is the correct way to write this?