我有一个查询,我希望在DLookup内设置查询参数:
查询 checkDate_Count_ForDangerousTickets:
SELECT count(*) AS numRelatedTickets
FROM DangrousTicketList
WHERE DateValue(backUpDate)>=DateValue(StartDate) And DateValue(backUpDate)<=DateValue(EndDate)
GROUP BY backUpDate;
我从dlookup
设置查询参数backUpDate
:
DLookUp("[numRelatedTickets]", "[checkDate_Count_ForDangerousTickets]", _
"[backUpDate]=" & Format("01-27-2013", "\#mm\/dd\/yyyy\#"))
我收到错误:
Run-time Error '2471'
The expression you entered as a query parameter produced this error:
'backUpDate'
好像查询参数backUpDate
由于某种原因没有设置。
答案 0 :(得分:3)
基于HansUp的评论和我自己的修补,我相信你将不得不使用一点VBA函数来运行你的参数查询:
Public Function LookupDangerousTicketCount(backUpDate As Date) As Variant
Dim qdf As DAO.QueryDef, rst As DAO.Recordset
Set qdf = CurrentDb.QueryDefs("checkDate_Count_ForDangerousTickets")
qdf!backUpDate = backUpDate
Set rst = qdf.OpenRecordset(dbOpenSnapshot)
If rst.BOF And rst.EOF Then
LookupDangerousTicketCount = Null
Else
LookupDangerousTicketCount = rst!numRelatedTickets
End If
rst.Close
Set rst = Nothing
Set qdf = Nothing
End Function
然后您可以使用
代替DLookup()
来电
LookupDangerousTicketCount(#2013-01-27#)