访问组合框值 [英] Access combobox value

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

问题描述

我有一个组合框和一个按钮,可以使用它从组合框获得的值运行查询,但它似乎没有获得正确的值.

I have a combobox, and a button, that makes runs a query with the values it gets from combobox, but it does not seem to get the right value.

我尝试使用

[Forms]![Kooli otsing]![Combobox] 

[Forms]![Kooli otsing]![Combobox].[Text]

查询无效,似乎没有从组合框获取值.因为它适用于普通的 TextBox.

the query did not work, it seems like it does not get the value from combobox. because it worked with normal TextBox.

我添加了说明图片!!!!!

I ADDED EXPLAINING PICTURE!!!!!

添加VBA编辑器图片

已添加错误图片且无评论自动完成

ADDED PICTURE OF ERROR AND NO COMMENT AUTOCOMPLETE

推荐答案

根据您针对问题发布的最新评论,您想使用:

Based on the latest comments you posted on your question, you want to use:

[Forms]![Kooli otsing]![Combo19].Column(1)

这就是原因.您说您的组合框有以下设置:

Here's why. You said you have the following settings for your combobox:

  • 列数:2
  • 绑定列:1
  • 行源类型:表/查询
  • 行源:SELECT [Haridusasutused].[ID], [Haridusasutused].[Nimetus] FROM Haridusasutused;

列数为 2 是告诉 Access 使用行源中的前两列(在这种情况下只有两列).绑定列告诉访问组合框的默认值应该是行源的第一列.在这种情况下,这将是 [Haridusasutused].[ID].ID 列通常是自动编号字段.

Column count of 2 is telling Access to use the first two columns from your rowsource (the only two columns in this case). Bound column is telling access that the default value of the combobox should be the first column of the row source. In this case, that would be [Haridusasutused].[ID]. Often ID columns are autonumber fields.

您遇到问题的原因是 [Forms]![Kooli otsing]![Combo19] 从 ID 列返回数据(很可能是数字)而不是Elva Gümnaasium".通过添加 .Column(1),您告诉 Access 从行源的第二列(.Column 是从零开始的数组)中选择数据,即,Elva Gümnaasium".

The reason you were having problems is that [Forms]![Kooli otsing]![Combo19] was returning data from the ID column (most likely a number) not "Elva Gümnaasium". By adding the .Column(1) you are telling Access to choose the data from the second column (.Column is a zero-based array) of the rowsource, ie, "Elva Gümnaasium".

EDIT:或者,您可以将绑定列从 1 更改为 2 并保留其余部分(即,您不需要 .Column(1) 部分.

EDIT: Alternatively, you can change the bound column from 1 to 2 and leave the rest alone (ie, you won't need the .Column(1) part at all).

这篇关于访问组合框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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