excel vba returns 中的记录集在 Access DB 中没有数据时
Recordset in excel vba returns nothing while data is present in Access DB
我是 运行 我在 excel 中的 VBA 代码,它连接并从 Access 中提取记录集。我有一个根据日期和 ID 进行选择的查询。我知道 table 中存在记录,但似乎当我添加日期条件时,记录集是空的。
我浏览了这个网站和我看到的每条建议,我都试过了,但我的记录集仍然是空的
这是我正在使用的代码:
'Here is the query
currentday = Format(Date, "dd-mm-yyyy")
extrct = "select * from Table1 where badge_ID=" & Me.BadgeInput & " " & "and date_pres=" & "#" & currentday & "#"
conn.Open (strconn)
rs3.Open extrct, conn, adOpenKeyset, adLockOptimistic, adCmdText
'This is where I check for any value is the recordset
If rs3.EOF And rs3.BOF Then -- This is coming out as True (no record)
GoTo 1
Else
GoTo 2
End If
我认为日期条件有问题,但考虑到我已经尝试了我所知道的一切,我无法弄清楚是什么
提前感谢您的帮助
由于您住在欧洲,因此必须对日期值表达式使用正确的格式:
currentday = Format(Date, "yyyy\/mm\/dd")
如果您这不仅仅是一个示例,并且您将始终使用今天的日期,只需使用:
extrct = "select * from Table1 where badge_ID = " & Me.BadgeInput & " and date_pres = Date()"
如果您存储了时间组件:
extrct = "select * from Table1 where badge_ID = " & Me.BadgeInput & " and Fix(date_pres) = Date()"
我是 运行 我在 excel 中的 VBA 代码,它连接并从 Access 中提取记录集。我有一个根据日期和 ID 进行选择的查询。我知道 table 中存在记录,但似乎当我添加日期条件时,记录集是空的。
我浏览了这个网站和我看到的每条建议,我都试过了,但我的记录集仍然是空的
这是我正在使用的代码:
'Here is the query
currentday = Format(Date, "dd-mm-yyyy")
extrct = "select * from Table1 where badge_ID=" & Me.BadgeInput & " " & "and date_pres=" & "#" & currentday & "#"
conn.Open (strconn)
rs3.Open extrct, conn, adOpenKeyset, adLockOptimistic, adCmdText
'This is where I check for any value is the recordset
If rs3.EOF And rs3.BOF Then -- This is coming out as True (no record)
GoTo 1
Else
GoTo 2
End If
我认为日期条件有问题,但考虑到我已经尝试了我所知道的一切,我无法弄清楚是什么
提前感谢您的帮助
由于您住在欧洲,因此必须对日期值表达式使用正确的格式:
currentday = Format(Date, "yyyy\/mm\/dd")
如果您这不仅仅是一个示例,并且您将始终使用今天的日期,只需使用:
extrct = "select * from Table1 where badge_ID = " & Me.BadgeInput & " and date_pres = Date()"
如果您存储了时间组件:
extrct = "select * from Table1 where badge_ID = " & Me.BadgeInput & " and Fix(date_pres) = Date()"