将组合框值传递到MS Access中的SQL查询中 [英] Passing combobox value into SQL query in MS Access

查看:74
本文介绍了将组合框值传递到MS Access中的SQL查询中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个组合框,并且希望将组合框的文本传递到查询中.

I have a combobox in a form, and I want the text of the combobox to be passed into a query.

我的查询是:

select..from..where something=[Forms]![Enter Data]![comboCup]

窗体的名称为Enter Data,组合框的名称为comboCup.我应该这样做吗?

The form's name is Enter Data and the combobox's name is comboCup. Should i do this:

[Forms]![Enter Data]![comboCup]![text]

还是这个?

[Forms]![Enter Data]![comboCup]![value]

推荐答案

您应使用[表单]![输入数据]![comboCup].

You should use [Forms]![Enter Data]![comboCup].

正如@Remou所说,仅当控件具有焦点时,Access控件的.Text属性才可用.

As @Remou has said, the .Text property of an Access control is available only when the control has the focus.

.Value属性是多余的,因为它是所有Access控件的默认属性,所以这两个等效:

The .Value property is redundant, as it's the default property of all Access controls, so these two are equivalent:

  [Forms]![Enter Data]![comboCup]
  [Forms]![Enter Data]![comboCup].Value

(还要注意,.Text和.Value之类的属性由点运算符而不是由bang来分隔集合)

(note also that properties like .Text and .Value are separated by the dot operator and not the bang, which delineates collections)

一个值得关注的问题是,是否要使用APPEND查询的SELECT语句中的组合框的值.在这种情况下,建议您在保存的查询中将组合框声明为参数.如果不这样做,则可能会导致未插入行,而如果声明了该参数,它将解析为Null,即引用的组合框中的值.

One issue that can be of concern is if you want to use the value of the combo box in the SELECT statement of an APPEND query. In that case, you would be advised to declare the combo box as a parameter in your saved query. If you do not, it can cause the row to not be inserted, whereas if you declare the parameter, it will resolve to the Null that is the value in the referenced combo box.

这篇关于将组合框值传递到MS Access中的SQL查询中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆