在Access/SQL/VB中从表单传递到查询 [英] Passing from Form to Query in Access/SQL/VB
本文介绍了在Access/SQL/VB中从表单传递到查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Access 2007/SQL/VB 我有一个查询:
Access 2007 / SQL / VB I have a query:
SELECT Count(*) AS CountOfCR1
FROM PData
WHERE (((PData.DestID)='CR1') And (((PData.AnswerTime)>=Starting)<Ending+1));
我正在尝试通过以下形式将变量开始"和结束"传递给上述查询:
I am trying to pass the variables Starting and Ending to the above query from the below form:
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
如何将表单的开始和结束传递给查询?
How can I pass Starting and Ending from my form to my query?
推荐答案
通常的方法是在查询中引用表单:
The usual way to do this is to refer to the form in the query:
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参数.
It is nearly always best to use a form with the recordsource set to the query or an sql string rather than opening a query. With a form, you can use the Where argument of the OpenForm method.
这篇关于在Access/SQL/VB中从表单传递到查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文