Access 2007 / SQL / VB 我有一个问题:
SELECT Count(*) AS CountOfCR1
FROM PData
WHERE (((PData.DestID)='CR1') And (((PData.AnswerTime)>=Starting)<Ending+1));
我正在尝试从以下表单将变量Starting和Ending传递给上面的查询:
Starting = StartDate & " " & StartTime
Ending = EndDate & " " & EndTime
On Error GoTo Err_Command5_Click
Dim stDocName As String
stDocName = "CountOfCR1 : Query"
DoCmd.OpenQuery stDocName, acNormal, acEdit
Exit_Command5_Click:
Exit Sub
Err_Command5_Click:
MsgBox Err.Description
Resume Exit_Command5_Click
如何将表格中的开始和结尾传递给我的查询?
答案 0 :(得分:0)
通常的方法是参考查询中的表单:
SELECT Count(*) AS CountOfCR1
FROM PData
WHERE PData.DestID='CR1'
And PData.AnswerTime Between Forms!MyForm!StartDate + Forms!MyForm!StartTime
And Forms!MyForm!EndDate + Forms!MyForm!SEndTime
几乎总是最好使用将记录源设置为查询的表单或sql字符串,而不是打开查询。使用表单,您可以使用OpenForm方法的Where参数。