ÁccessVBA:如何获取表单中的输入并在查询中使用它们 [英] Áccess VBA:How to get input in forms and use them in queries
问题描述
我有一个有几个按钮的表单。每个按钮都会运行几行代码。代码中也有查询,比如select * from table where number = 6现在如果我想给出这个数字作为表单中的输入,我该如何处理它。 添加一个未绑定的文本靠近你的按钮控制。 更新您的按钮代码以生成查询字符串: ; me.controls(myControlName)。value
您可能觉得需要确保myControlName控件只允许数字/不接受null ,或治疗您的手术中的所有病例
如果Isnull(me.controls(myControlName)。value)则
else
如果isnumeric(me.controls(myControlName ).value)然后
myQuery = myQuery& WHERE myNumber =& me.controls(myControlName)。value
else
msgBox me.controls(myControlName)。value& 不被接受
退出功能
Endif
Endif
HI
I have a form with a few buttons. Each button runs a few lines of code.the code have queries also in them like "select * from table where number =6"
now if i want to give the number as a input in the form, how do i go about it.
- Add an unbound text control close to your button.
Update your button code to generate the query string as :
"SELECT * FROM myTable WHERE myNumber =" & me.controls("myControlName").value
You might feel the need to make sure that the "myControlName" control allows only numbers/do not accept null, or treat all cases in your procedure
myQuery = "SELECT * FROM myTable"
If Isnull(me.controls("myControlName").value) then
Else
If isnumeric(me.controls("myControlName").value) then
myQuery = myQuery & " WHERE myNumber =" & me.controls("myControlName").value
Else
msgBox me.controls("myControlName").value & " is not accepted"
Exit function
Endif
Endif
这篇关于ÁccessVBA:如何获取表单中的输入并在查询中使用它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!