vba 根据另一个字段过滤查找字段
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19018210/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Filtering A Lookup Field Based On Another Field
提问by Muhnamana
I have a lookup field in my table based on another table. I'm having trouble filtering those values based on another field that is entered prior to the field.
我的表中有一个基于另一个表的查找字段。我无法根据在该字段之前输入的另一个字段过滤这些值。
Is it possible to filter a lookup field based on another field?
是否可以根据另一个字段过滤查找字段?
EDIT
编辑
Let me try and clarify my original question, sorry about that. Ok, so I have a table1 that has the following fields: ID, Name, Logo.
让我试着澄清我最初的问题,对此感到抱歉。好的,所以我有一个 table1,其中包含以下字段:ID、名称、徽标。
If a user enters a specific name in the Name field, when they click on the Logo field, it'll only display those values associated that are similar to the name entered. Does that make any sense? If it does make sense, would there be an easier suggesion on accomplishing this task?
如果用户在“名称”字段中输入特定名称,则当他们单击“徽标”字段时,它只会显示与输入的名称相似的关联值。这有任何意义吗?如果确实有意义,是否有更简单的建议来完成这项任务?
回答by Johnny Bones
If you're talking about inside a table, the answer is "No". You can create cascading combo boxes on a form, but you can't base a lookup value in a field of a table off of a different field in that table (or the field in any other table).
如果您是在桌子内谈论,答案是“否”。您可以在表单上创建级联组合框,但不能将表的字段中的查找值基于该表中的不同字段(或任何其他表中的字段)。
回答by Linger
Here is an example of how to handle filtering a combo box based on the value selected in another combo box:
以下是如何根据另一个组合框中选择的值处理组合框过滤的示例:
I have the following form:
我有以下表格:
The combo boxes are named cboIntPN
and cboManPN
.
组合框被命名为cboIntPN
和cboManPN
。
The Row Source for cboIntPN
is set to: SELECT uniq_key, part_no, revision FROM inventor
. The Row Source for cboManPN
isn't set to anything.
的行源cboIntPN
设置为:SELECT uniq_key, part_no, revision FROM inventor
。行源cboManPN
未设置为任何内容。
When the user selects a value for Internal PN the following AfterUpdate Event is triggered:
当用户为内部 PN 选择一个值时,将触发以下更新后事件:
Private Sub cboInternalPN_AfterUpdate()
[cboManPN].RowSourceType = "Table/Query"
[cboManPN].RowSource = "SELECT uniqmfgrhd, mfgr_pt_no FROM invtmfhd " & _
"WHERE uniq_key = '" & cboIntPN.value & "'"
End Sub