无法在连续表单上设置 ComboBox.RowSource
我在设置表单上某个组合框的行源时遇到问题(被视为连续表单,尽管我在单表单模式下似乎也遇到了一些问题)。
该组合框绑定到一个名为 supplierID
的字段,旨在向用户显示某个项目的所有可能供应商的列表。我用于组合框的行源是:
SELECT DISTINCT Suppliers.name, Suppliers.supplierID
FROM Suppliers
INNER JOIN PartsSuppliers ON Suppliers.supplierID=PartsSuppliers.supplierID
WHERE PartsSuppliers.partID = partID;
当我在查询设计器中查看此查询时(使用硬编码的partID),它工作正常 - 它为所选项目选择所有可能的供应商,并且不'不显示任何其他项目。但是,当我查看组合框中的项目时,它显示了 PartsSuppliers
表中存在的所有供应商(该表只有两列,将零件映射到可能的零件)他们的供应商)。
我还尝试在 OnFocus 事件中使用一些 VBA 设置组合框的 RowSource(对 partID 值进行硬编码),但它似乎从未更改 RowSource。我使用的 VBA 代码是:
Private Sub supplierID_GotFocus()
Dim query As String
query = "SELECT DISTINCT Suppliers.name, PartsSuppliers.supplierID "
query = query & "FROM Suppliers INNER JOIN PartsSuppliers ON Suppliers.supplierID = PartsSuppliers.supplierID "
query = query & "WHERE (((PartsSuppliers.partID)=" & partID & "));"
supplierDropDown.RowSource = query
supplierDropDown.Requery
End Sub
我还尝试在 RecordSet 中打开该查询,然后将该 RecordSet 设置为组合框的 RecordSet,但这也不起作用。
我做错了什么,或者我应该寻找其他方法来做出正确的下拉菜单?
注意我已经看到 组合框的自定义行源在 Access 中以连续形式,但接受的解决方案对我来说也不起作用。
I am having trouble setting the row source of a certain combo box on my form (viewed as a continuous form, although I also seem to have some problems in single-form mode).
The combo-box is bound to a field called supplierID
, and is meant to present the user with a list of all the possible suppliers for an item. The row-source I am using for the combo-box is:
SELECT DISTINCT Suppliers.name, Suppliers.supplierID
FROM Suppliers
INNER JOIN PartsSuppliers ON Suppliers.supplierID=PartsSuppliers.supplierID
WHERE PartsSuppliers.partID = partID;
When I view this query in the query designer (with a partID hard-coded), it works fine - it selects all the possible suppliers for the chosen item, and doesn't show any other items. But when I look at the items in the combo-box, it shows all the suppliers present in the PartsSuppliers
table (which has just two columns, mapping the parts to the possible suppliers for them).
I have also tried to set the combo-box's RowSource using some VBA in the OnFocus event (hardcoding the partID value in), but it never seems to change the RowSource. The VBA code I am using is:
Private Sub supplierID_GotFocus()
Dim query As String
query = "SELECT DISTINCT Suppliers.name, PartsSuppliers.supplierID "
query = query & "FROM Suppliers INNER JOIN PartsSuppliers ON Suppliers.supplierID = PartsSuppliers.supplierID "
query = query & "WHERE (((PartsSuppliers.partID)=" & partID & "));"
supplierDropDown.RowSource = query
supplierDropDown.Requery
End Sub
I also tried opening that query in a RecordSet, and then using setting that RecordSet as the combo-box's RecordSet, but that didn't work either.
What am I doing wrong, or is there some other way that I should be looking at to make the correct drop down?
N.B. I have seen Custom row source for combo box in continuous form in Access, but that accepted solution didn't work for me either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
OnEnter
和OnExit
事件更改您的RowSource
。Use the
OnEnter
andOnExit
events to change out yourRowSource
.一旦组合项目受到限制,我一直在努力解决如何避免数据表中留下的“空白”,并且很长一段时间找不到任何直接的选项......直到现在!
将所有可用选项保留在组合框中,但使用 OnCurrent 添加临时验证规则,可以完美地实现这一目的。
希望这可以防止有人像我一样长时间用头撞桌子。
I've been struggling with how to avoid the 'blanks' left behind in a datasheet once Combo items are restricted and couldn't find any straight forward option for a long time....until now!
Leaving all of the available options in the Combo box but adding a temporary validation rule, using OnCurrent, does the trick perfectly.
Hoping this prevents someone banging their head on the desk for as long as I have.