0
votes

I have a user inputed date format of mm/dd/yyyy. I want to use this input in a query to act as a filter (start and end time). The actual date stored in the datebase was set with now(), so it has the format mm/dd/yyyy XX:XX:XX AM/PM.

How can I use these inputed dates in my filter? (When I tried out an mm/dd/yyyy input I was returned a Report with no values, but if I added the time, it worked, but I don't want the user to have to enter the time.)

Right now I am using simple input boxes for the input. I really would like to create a calendar popup (and I see tutorials online). Would the solution change if I changed over to a Calendar?

EDIT: Here is my code, to make it eaiser to understand the issue.

Dim startDate As Date
Dim endDate As Date

startDateString = InputBox("Enter a start date.")
endDateString = InputBox("Please enter and end date.")

Reports![rpt_Inventory_Update].RecordSource = "MyQuery"
Reports![rpt_Inventory_Update].Filter = "Modification_Date BETWEEN #" & startDate & "# AND #" & endDate & "#"
Reports![rpt_Inventory_Update].FilterOn = True
2

2 Answers

1
votes

When you compare to the field with Now(), you could change it to be compared to DateValue(Now())

Now() = Date() returns False
DateValue(Now()) = Date() returns True

0
votes

I figured it out. This is my new code:

startTime = TimeValue("00:00:00")
endTime = TimeValue("23:59:59") 
startDate = startDate + startTime
endDate = endDate + endTime

Reports![rpt_Inventory_Update].RecordSource = "MyQuery"
Reports![rpt_Inventory_Update].Filter = "Modification_Date BETWEEN #" & startDate & "# AND #" & endDate & "#"
Reports![rpt_Inventory_Update].FilterOn = True

This makes sure that the start and end dates in the query have a full time stamp, and thus the query works!