All ...
I need to display records that are between the two dates passed in from DateTimePickers.
I am getting records that are NOT in between the dates that I sp
Your problem seems to be in the way you parse passed date parameters to the query and they're probably not in format that Access would recognize as a valid Date type. Try with CDate()
function to let Access parse your input values to its internal date type properly. It will accept any valid date expression
:
Any expression that can be interpreted as a date, including date literals, numbers that look like dates, strings that look like dates, and dates returned from functions. A date expression is limited to numbers or strings, in any combination, that can represent a date from January 1, 100 – December 31, 9999.
Your code could thus look like this:
str1 = "SELECT * FROM Inquiry_Details WHERE Inquiry_Date>=CDate('" &
dtp_inq_from.Text & "') AND Inquiry_Date<=CDate('" &
dtp_inq_to.Text & "')"
Another function that you might want to try (if CDate
won't cut it) is DateValue()
:
The required date argument is normally a string expression representing a date from January 1, 100 through December 31, 9999. However, date can also be any expression that can represent a date, a time, or both a date and time, in that range.
The success of these two functions might also depend on input date formatting and system locale.