问题描述
使用所有补丁访问2007
Access 2007 with all patches
假设我有一个用于选择州(即NY)的组合框。引用表(table1)有两个字段:PrimaryKey AutoNumber State Text
Assume I have a combobox for selecting a state (i.e. NY). The reference table (table1) has two fields: PrimaryKey AutoNumber State Text
表单的数据源是一个包含两个字段的表(table2):PrimaryKey AutoNumber StateID Number
The data source for the form is a table (table2) with two fields: PrimaryKey AutoNumber StateID Number
组合框控制源是StateID组合框行源是:SELECT * FROM [table1] ORDER BY [State];组合框限制列表是:是
The combobox Control Source is StateID The combobox Row Source is: SELECT * FROM [table1] ORDER BY [State]; The combobox Limit To List is: Yes
(在下面的描述中输入的数据没有框架引号。)
(In the description below the data is entered without the framing quotes.)
如果"自动展开"为"是",用户键入"N"。组合框显示以"N"开头的第一个条目。如果用户键入"NY",则(带有尾随空格)并按Tab键触发Not In List事件。
If Auto Expand is Yes and the user types in "N" the combobox displays the first entry starting with "N". If the user types in "NY " (with a trailing space) and presses tab the Not In List event is triggered.
如果"自动展开"为"否",则用户键入"N"组合框仅显示"N"。如果用户键入"NY",则(带有尾随空格)并按下选项卡不会触发Not In List事件,并且将table1中的NY记录的密钥插入到table2中。
换句话说,"纽约"是指"纽约"。被映射到"NY"。并选择该记录的密钥。
If Auto Expand is No and the user types in "N" the combobox only displays "N". If the user types in "NY " (with a trailing space) and presses tab the Not In List event is not traiggered and the key for the NY record from table1 one is inserted into table2. In other words the "NY " is mapped to "NY" and the key for that record is selected.
如果"自动展开"为"否",则用户手册会打开下拉列表并输入"N"。列表中以"N"开头的第一个条目被选中。如果用户键入"NY",则并按下Tab键,触发Not In List事件。
If Auto Expand is No and the user manual opens the dropdown list and types in "N" the first entry in the list starting with "N" is selected. If the user types in "NY " and presses tab the Not In List event is triggered.
现在文本框的正常逻辑(以及组合框是文本框和列表框的组合)是截断尾随空格。如果您有一个文本框绑定到表格中的文本字段并输入"NY",表中字段中的值将是"NY"。保存
记录时
Now the normal logic for a textbox (and a combobox is a combination of a textbox and a listbox) is to truncate trailing spaces. If you have a textbox bound to a text field in a table and enter "NY " the value in the field in the table will be "NY" when the record is saved.
这是组合框的预期行为还是由于最近的更新?它在Access 2007 RTM中是否以这种方式运行?如果这是组合框的预期行为,它背后的逻辑是什么?那就是为什么这样设计呢?
Is this the expected behavior for the combobox or is this due to a recent update? Does it behave this way in Access 2007 RTM? If this is the expected behavior for the combobox what is the logic behind it? That is, why was it designed this way?
推荐答案
OTOH,我可以猜测,推理可能类似于自动扩展是在用户输入的键操作之后,并且在用户点击输入,制表符等之前不会修剪尾随空格。
OTOH, I can guess that the reasoning might be something like auto expand is operating off of the keys the user entered and trailing spaces are not trimmed until the user hits enter, tab , etc.
如果你的用户习惯在他们想要输入的数据后输入额外的空格,然后我不会使用NotInList事件。 相反,我会尝试使用Before(或After?)Update事件来检查用户数据是否在列表中:
If your users are in the habit of entering extra spaces after the data they want to enter, then I would not use the NotInList event. Instead, I would try to use the Before (or After?) Update event to check if the user data was in the list:
如果Me.combobox.ListIndex = -1则为
MsgBox"不在列表中的数据"&b $ b 。 。 。$
结束如果
If Me.combobox.ListIndex = -1 Then
MsgBox "data in not in the list"
. . .
End If
这篇关于组合框和尾随空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!