Access form cascading combo box shows nothing in drop down menu

时间:2017-08-30 20:31:14

标签: mysql ms-access combobox cascadingdropdown ms-access-2016

I am trying to create a data entry form with cascading combo boxes to limit the users options. I had it working for a bit, then it decided to quit. I could just be overthinking it all though.

There are going to be about 50 boxes that I will have to set up. The first is a one to many. I got the first box to add to a new record correctly. When I get to the second combobox, the dropdown menu shows nothing. It's fine until I enter [forms]![NewSpecForm]![cboBoxSize] in the criteria. How do I create cascading combo boxes that will actually work permanently?

My third combo box is a many to many, so I created a junction table for that. I have found several tutorials on how to join the tables for cascading combobox and once I had that working, the first and second boxes weren't adding the correct info to the new record.

If I leave the AfterUpdate alone and have the second box on its own, it's adding the ID to the new record instead of the name. How do I fix that?

1 个答案:

答案 0 :(得分:0)

首先,让我们确保理解“级联组合框”背后的概念。逻辑运行的方式是,在您从Combo1中进行选择后,Combo2中可用的选项将更改,以便它们只是与Combo1相关的项目。同样,在我们从Combo2中选择一个项目后,Combo3中的项目将只是与用户在Combo2中选择的内容相关的项目。

因此,首先,除了Combo1之外,每个组合框都应该为空,或者应该与Combo1的默认值相关。你可以这样做。

接下来,在Combo1的AfterUpdate事件中,您应该具有以下内容:

Me.cboCombo2.RowSource = "SELECT MyFieldNames " & _
                           "FROM tblMyTable " & _
                           "WHERE SomeID = " & Nz(Me.cboCombo1) & _  
                           "ORDER BY SomeValue"
Me.cboCombo2.Requery

显然,MyFieldNames,tblMyTable以及所有其他值将取决于您实际查找的内容,源表/查询名称和字段名称等等。

好的,所以现在Combo2应该填充与您在Combo1中选择的内容相关的数据,因为我们在上面的SQL中使用Combo1作为过滤器。

如果看起来没问题,请为Combo3做更多或更少的事情。您可能需要对两个组合中的值进行过滤,或者您可以在Combo2中使用该值,具体取决于您的数据集。

泡沫,冲洗,重复。如果你有50个组合,我想你需要这样做50次,但这就是它的完成方式。

有关详细信息,请参阅此文章:http://www.fmsinc.com/microsoftaccess/forms/combo-boxes/cascading.html