我认为我的查询语法错误,我找不到错误。我在" 1/1/1990"得到了错误。有人知道我在这里做错了吗?
Set rsCanCounter = db.OpenRecordset("Select * from tblActionLog Where groupNum = '" & txtGroupNr.Value & "' And DateClosed < '" & 1/1/1900, dbOpenDynaset)
答案 0 :(得分:2)
使用字符串变量来保存SELECT
语句。在克服引用问题后,您可以在VBA中创建有效字符串,然后将该变量与OpenRecordset
一起使用。
例如,如果 groupNum 和 DateClosed 字段的数据类型都是文本...
Dim strSelect As String
strSelect = "Select * from tblActionLog Where groupNum ='" & _
Me.txtGroupNr.Value & "' And DateClosed < '1/1/1900'"
Debug.Print strSelect '<-- Ctrl+g to go to Immediate window and see the statement text
Set rsCanCounter = db.OpenRecordset(strSelect, dbOpenDynaset)
如果 DateClosed 是日期/时间数据类型,请使用#
而不是引号来分隔日期值:
strSelect = "Select * from tblActionLog Where groupNum ='" & _
Me.txtGroupNr.Value & "' And DateClosed < #1900-1-1#"