SQL String with Dates (1 Viewer)

RaabiAnony

New member
Local time
Today, 19:16
Joined
Aug 28, 2016
Messages
1
Hello everybody!
This is my first post about a problem in MS Access. I am using the following statements:

Code:
Dim dtStart As Date
Dim dtEnd As Date
Dim strSql As String
rptName = "rptStudentsByDoB"
          
dtStart = Me.txtDateStart.Value
dtEnd = Me.txtDateEnd.Value
strSql = "Select * From tblStudents " & _
              " WHERE DoB < '" & dtStart & "' AND DoB > '" & dtEnd & "'"
strSql = "Select * From tblStudents " & _
              " WHERE DoB Between #" & dtStart & "# AND #" & dtEnd & "#"
strSql = "select * from tblStudents where DoB BETWEEN " & dtStart & " AND " & dtEnd
All the three statements return the same error as follows:
Syntx error (missing operator) in query expression
Code:
DoB < #dtStart# DoB > #dtEnd#
It drops the Operator 'AND' from all the statements.
Would anyone help in sorting out this problem, please!

Regards
 

Cronk

Registered User.
Local time
Tomorrow, 02:16
Joined
Jul 4, 2013
Messages
2,770
Try
strSql = "Select * From tblStudents " & _
" WHERE DoB Between #" & format(dtStart,"mm/dd/yyyy") & "# AND #" & format(dtEnd,"mm/dd/yyyy") & "#"
 

Users who are viewing this thread

Top Bottom