我想在VBA中运行一个delete查询,以删除包含大于预先计算的当前月份的计费月份的记录。来自另一个系统的源数据具有文本格式的日期,显示为(YYYY/MM)。
以下是声明:
mySQL = "DELETE * FROM [tblBillingData]" _
& "WHERE (((tblBillingData.[Billing Month]) > PreCalcCurrentMonth));"
DoCmd.RunSQL mySQL所有变量都被正确声明,当我单步执行代码时,我可以看到PreCalcCurrentMonth,但是当它运行SQL语句时,我会看到PreCalcCurrentMonth变量的Enter Parameter输入框。
发布于 2013-02-20 04:31:27
假设PreCalcCurrentMonth是一个日期变量,尝试如下所示:
mySQL = "DELETE * FROM [tblBillingData]" & _
"WHERE (((tblBillingData.[Billing Month]) > " & _
Format(PreCalcCurrentMonth,"\#mm\/dd\/yyyy\#") & _
"));"
DoCmd.RunSQL mySQLFormat(PreCalcCurrentMonth,"\#mm\/dd\/yyyy\#")可确保您的日期转换为美国日期格式#mm/dd/yyyy#的字符串,无论您的区域设置如何。#是日期分隔符。
发布于 2013-02-20 04:31:58
试试这个:
mySQL = "DELETE * FROM [tblBillingData]" _
& "WHERE (((tblBillingData.[Billing Month]) > #" & PreCalcCurrentMonth & "#));"首先,您需要将变量作为字符串外部的变量引用,否则,Access VBA会认为它是一个字符串。
其次,您需要用#符号将日期参数括起来。
https://stackoverflow.com/questions/14966612
复制相似问题