正如@MicSim 向您展示的那样,您的直接问题是缺少# 日期分隔符。但是,我建议您为 WHERE 子句考虑一种不同的方法。
您的 WHERE 子句在添加 # 分隔符后与此类似(带有今天的日期)。
Debug.Print "WHERE pdate not between #1-" & _
Format$(Now, "MMM") & "-" & Format$(Now, "YYYY") & _
"# and #20-" & Format$(Now, "MMM") & "-" & _
Format$(Now, "YYYY") & "#"
WHERE pdate not between #1-May-2011# and #20-May-2011#
一个重要的问题是您的所有日期值是否都包含午夜作为时间部分。 (日期/时间值始终包含时间部分。)这可能很重要的原因是,对于 2011 年 5 月 20 日上午 10:18:15 的日期,本月应该发生什么?您的 WHERE 子句将导致更新。但是那个日期仍然是 5 月 20 日……这是你想要的吗?
我认为修改后的 WHERE 子句会降低意外后果的风险。
Debug.Print "WHERE pdate < " & _
Format(DateSerial(Year(Date), Month(Date), 1), "\#yyyy-mm-dd#\") & _
" OR pdate >= " & _
Format(DateSerial(Year(Date), Month(Date), 21), "\#yyyy-mm-dd#\")
WHERE pdate < #2011-05-01# OR pdate >= #2011-05-21#
您的问题已标记为 vb6。 DateSerial()、Year()、Month()、Date() 和 Format() 函数都应该在数据库引擎的沙盒模式下可用。 (见Microsoft's page about sandbox mode functions)。
编辑:感谢@Brian Camire 的建议。
Debug.Print "WHERE pdate < " & _
"DateSerial(Year(Date), Month(Date), 1)" & _
" OR pdate >= " & _
"DateSerial(Year(Date), Month(Date), 21)"