Using CDate in a SQL WHERE clause For Access database

  • Thread starter Thread starter SequimMike
  • Start date Start date
S

SequimMike

Guest
I have an Access Database table in which I store dates as strings in field VisitDate in a Short Date format "09/29/2020". There is another String field 'ApName' In this table. If I create a where clause like:

dim WHEREClause as string = String.Empty

dim strDt as string = "01/01/2020"

dim endDt as string = "10/29/2020"

dim LLName as string = "Elk Creek Apt."

WHEREClause = " WHERE ApName = '" & LLName & "' And CDate(VisitDate) BETWEEN #" & strDt & "# And #" & endDt & "#"

and run an SQL SELECT call. it returns all the correct entries.

If I use a where clause like:

WHEREClause = " WHERE CDate(VisitDate) BETWEEN #" & strDt & "# And #" & endDt & "#"

and run an SQL SELECT call, it returns an error 'Data type mismatch in criteria expression.' What am I doing wrong here? Thanks for any help you can give me. I've been struggling with this problem for over a year now.

Continue reading...
 
Back
Top