I am getting a data type mismatch with the following code. However, it looks fine when I do a debug print.
Dim strSQL As String
Dim StartDate As Date
Dim EndDate As Date
StartDate = “1/1/2019”
EndDate = “2/1/2019”
strSQL = SELECT Table1.Start INTO 1 FROM Table1 WHERE (((Table1.Start) BETWEEN ‘“ & StartDate & “‘“ & “ AND ‘“ & EndDate & “‘));”
Debug.Print strSQL
Docmd.RunSQL strSQL
Use the correct syntax for dates and date value expressions:
Dim strSQL As String
Dim StartDate As Date
Dim EndDate As Date
StartDate = #1/1/2019#
EndDate = #2/1/2019#
strSQL = "SELECT Table1.Start INTO 1 FROM Table1 WHERE (((Table1.Start) BETWEEN #" & Format(StartDate, "yyyy\/mm\/dd") & "# AND #" & Format(EndDate, "yyyy\/mm\/dd") & "#);"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.