Date parameter with Date/Time values (1 Viewer)

nschroeder

nschroeder
Local time
Today, 17:05
Joined
Jan 8, 2007
Messages
186
I have a field in a table containing date/time values, and want to use a parameter query with a form from which the user can enter a value in a date picker textbox. When a date is entered, however, no matching records are found because of the time in the field values.

I can get it to work by putting two date fields on the form for a beginning and ending date range, and then enter today's date in the beginning field and tomorrow's in the ending field. It will then include all of today's records, but is there a simpler way?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 15:05
Joined
Aug 30, 2003
Messages
36,124
In your query, use DateAdd() on the end date textbox to add a day to whatever is entered. If times could include midnight, you might want to add minutes or seconds instead.
 

nschroeder

nschroeder
Local time
Today, 17:05
Joined
Jan 8, 2007
Messages
186
I see your point. I also have another problem. I have the date picker textbox defined with a format of Short Date, and that's the way it appears when the field doesn't have focus, but if I click in it, it shows up as date/time. Not only is it ugly, but it affects the query results, because it will only include records after the current time value. In other words, if the current time is 10:56 and I select 12/1/2017 in the date picker, it will only include records between 12/1/17 10:56 AM and 12/2/17 10:56 AM (using your DateAdd suggestion).
 

Minty

AWF VIP
Local time
Today, 23:05
Joined
Jul 26, 2013
Messages
10,366
Put an after update event to tidy it up, then your query will still be efficient, something like

Me.YourStartDate = DateValue(Me.YourStartdate)
 

nschroeder

nschroeder
Local time
Today, 17:05
Joined
Jan 8, 2007
Messages
186
I found the problem. In FormLoad, I had tbReportDate = Now() instead of Date(). My bad!
 

Users who are viewing this thread

Top Bottom