0

I have a problem with Access 2013.

I am doing a query to get the records that have dates smaller than the date included in a form. But, I'm getting wrong results. I don't know if that is an Access' issue or I'm doing something wrong.

Me.txtResultsForm.RowSource = " SELECT number FROM TBL_Course WHERE TBL_Course.finalDate <= #" & Format(Me.txtFinalDateForm, "dd/mm/yyyy") & "# "

I tried of this way too, but I get the same results:

Me.txtResultsForm.RowSource = " SELECT number FROM TBL_Course WHERE TBL_Course.finalDate <= #" & Me.txtFinalDateForm & "# "

Help!!!!!

David Knipe
  • 3,417
  • 1
  • 19
  • 19
  • You can make your question a bit easier to read by using the code tags. You can edit your question by clicking on "edit" button. – Gabriel Devillers Nov 14 '18 at 22:28
  • Stop concatenating SQL. Use parameterized queries instead, and let the database driver worry about formatting dates properly. – Ken White Nov 14 '18 at 23:16

1 Answers1

1

Fully agree with Ken's comment - see this excellent answer from Erik von Asmuth for how to use parameterised queries.


As for your issue, you'll need to change:

Format(Me.txtFinalDateForm, "dd/mm/yyyy")

to:

Format(Me.txtFinalDateForm, "mm/dd/yyyy")
Lee Mac
  • 15,615
  • 6
  • 32
  • 80