vba 如何根据另一个组合框选择过滤组合框选择列表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4170582/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 12:17:28  来源:igfitidea点击:

How can i filter a combobox selection list based on another combobox selection

ms-accessvba

提问by WannaBeCodeMonkey

I'm sure this question may have been asked to death, but I cant find any answer that i can get to work. Basically I would like to have two combobox controls. One box selects an armor type for example. The next box would show only those unit types that have the armor type selected. I'm complete crap when it comes to SQl and very limited with my VBA, but would prefer a response in VBA since I understand it better. Any help in this matter would be great. please and thank you

我确定这个问题可能已经被问到死了,但我找不到任何可以开始工作的答案。基本上我想要两个组合框控件。例如,一个框选择一种盔甲类型。下一个框将仅显示选择了装甲类型的那些单位类型。当涉及到 SQl 时,我完全是废话,而且我的 VBA 非常有限,但更喜欢在 VBA 中做出响应,因为我更了解它。在这件事上的任何帮助都会很棒。谢谢,麻烦您了

回答by hol

There are many ways to achieve this.

有很多方法可以实现这一目标。

For example: In the first combo box implement an Event "On Change". Do some VBA coding in it to fill up the second combo box based on the value selected on the first combo box. See a VBA example below

例如:在第一个组合框中实现一个事件“On Change”。在其中执行一些 VBA 编码以根据在第一个组合框中选择的值填充第二个组合框。请参阅下面的 VBA 示例

There are tons of tutorials if you google for "access combo box based on another".

如果您在 google 上搜索“基于另一个的访问组合框”,则有大量教程。

Private Sub Combo1_Change()

    If Me.Combo1.Value = "value1" Then
        Me.Combo2.RowSource = "val 1 based on 1;value 2 based on 1"
    End If

    If Me.Combo1.Value = "value2" Then
        Me.Combo2.RowSource = "val 1 based on 2;value 2 based on 2"
    End If
End Sub

回答by Fionnuala

This is a common question, and a search for "cascading combobox" will return a number of answers, for example, MS Knowledge base has How to synchronize two combo boxes on a form in Access 2002 or in Access 2003and one from Stackoverflow : Is there a simple way of populating dropdown in this Access Database schema?

这是一个常见问题,搜索“级联组合框”将返回许多答案,例如,MS 知识库具有如何同步 Access 2002 或 Access 2003 中的表单上的两个组合框以及 Stackoverflow 中的一个:是在此 Access 数据库架构中是否有一种简单的方法来填充下拉列表?