Access 中连续形式的组合框的自定义行源 [英] Custom row source for combo box in continuous form in Access

查看:16
本文介绍了Access 中连续形式的组合框的自定义行源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我四处搜索,似乎这是 MS Access 中的一个限制,所以我想知道其他人找到了哪些创造性的解决方案来解决这个难题.

I have searched around, and it seems that this is a limitation in MS Access, so I'm wondering what creative solutions other have found to this puzzle.

如果您有一个连续的表单并且您希望一个字段成为特定于该行的选项组合框,Access 将无法提供;组合框行源仅在表单开头查询一次,因此会为表单的其余部分显示错误的选项.

If you have a continuous form and you want a field to be a combo box of options that are specific to that row, Access fails to deliver; the combo box row source is only queried once at the beginning of the form, and thus show the wrong options for the rest of the form.

当然,我们都尝试的下一步是使用 onCurrent 事件重新查询组合框,这实际上将选项限制为给定的行.然而,在这一点上,Access 发疯了,并为每一行重新查询所有组合框,结果通常是在其他行中消失和重新出现选项,这取决于他们是否选择了对当前记录的行源有效的选项.

The next step we all try, of course, is to use the onCurrent event to requery the combo box, which does in fact limit the options to the given row. However, at this point, Access goes nuts, and requeries all of the combo boxes, for every row, and the result is often that of disappearing and reappearing options in other rows, depending on whether they have chosen an option that is valid for the current record's row source.

我找到的唯一解决方案是始终列出所有可用选项.有什么有创意的答案吗?

The only solution I have found is to just list all options available, all the time. Any creative answers out there?

编辑 另外,我要注意组合框的原因是有一个查询作为查找表,需要隐藏和存储真实值,而显示人类可读的版本...组合框行源中的多列.因此,将限制更改为列表无济于事,因为不在当前行源查询中的 id 将没有匹配的人类可读部分.

Edit Also, I should note that the reason for the combo box is to have a query as a lookup table, the real value needs to be hidden and stored, while the human readable version is displayed... multiple columns in the combo box row source. Thus, changing limit to list doesn't help, because id's that are not in the current row source query won't have a matching human readable part.

在这种特殊情况下,连续形式很有意义,所以请不要告诉我这是错误的解决方案.我要求任何有创意的答案.

In this particular case, continuous forms make a lot of sense, so please don't tell me it's the wrong solution. I'm asking for any creative answers.

推荐答案

我也讨厌 Access,但你必须玩弄你拿到的牌.连续表单在 Access 中是一件很棒的事情,直到您遇到任何类型的复杂情况,这是常见的情况,例如在本例中.

I also hate Access, but you must play with the cards you are dealt. Continuous forms are a wonderful thing in Access, until you run into any sort of complexity as is commonly the case, like in this instance.

这是我在面对这种情况时会做的事情(我之前也实施过类似的解决方法):

Here is what I would do when faced with this situation (and I have implemented similar workarounds before):

在表单上放置一个 UNBOUND 组合框.然后为要编辑的字段放置一个绑定文本框.

Place an UNBOUND combobox on the form. Then place a BOUND textBox for the field you want to edit.

确保组合框隐藏在文本框后面(不是不可见,只是隐藏).

Make sure the combobox is hidden behind (NOT invisible, just hidden) behind the textBox.

在 OnCurrent 事件中,用必要的数据填充列表框.继续并限制列出"它.

In the OnCurrent event fill the listBox with the necessary data. Go ahead and "Limit to list" it too.

在文本框的 OnEnter 或 OnClick 事件中赋予组合框焦点.这会将组合框带到最前沿.当焦点离开组合框时,它将再次隐藏自己.

In the OnEnter or OnClick event of the textBox give the combobox focus. This will bring the combobox to the forefront. When focus leaves the combobox it will hide itself once more.

在组合框的 AfterUpdate 事件中,将文本框的值设置为等于组合框的值.

In the AfterUpdate event of the combobox set the value of the textbox equal to the value of the combobox.

根据您的情况,可能还有一些其他细节需要解决,但这或多或少应该可以实现您的目标,而不会增加太多复杂性.

Depending on your situation there may be some other details to work out, but that should more or less accomplish your goal without adding too much complexity.

这篇关于Access 中连续形式的组合框的自定义行源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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