简体   繁体   English

将变量传递到sql查询时,ms访问数据类型在条件表达式中不匹配

[英]ms access data type mismatch in criteria expression when passing a variable into a sql query

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 调试打印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") & "#);"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM