subform combobox rowsource update - 如何更新下拉列表 [英] subform combobox rowsource update - how update drop down list

查看:230
本文介绍了subform combobox rowsource update - 如何更新下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MS Access窗体上的treeview控件。子窗体组合框控件的值列表取决于在主窗体上的树视图中选择的节点。
我试图刷新子表单上的组合框下拉列表内容,如下所示:

I have a treeview control on an MS Access form. A subform combo box control's list of values depends on the node selected in the treeview on the main form. I am trying to achieve refresh of the combo box drop down list contents on the subform as follows:

Public Sub TreeView1_nodeClick(ByVal node As Object)
    subForm.Controls("Bid").RowSource = "... newquery depending on tree node values ..."
    subForm.Controls("Bid").Requery
End Sub

但奇怪的是,这不会更新值列表。
第二次单击同一节点不会将列表更新为预期值;当另一个节点被点击时,列表再次是错误的(它包含与下一个最后分配的rowsource相关的列表,而不是与分配的最后一个相关)。

But oddly enough, this does not update the list of values. A second click on the same node does update the list to the expected values; when another node is clicked the list again is wrong (it contains the list related to the next to last assigned rowsource, instead of related to the last one assigned).

在激活组合框'rowsource有一些延迟?

这个讨厌的问题的解决方案是什么?

Is there some delay in activating the combo box' rowsource?
What is the solution for this obnoxious problem?

推荐答案

p> OK找到了一个解决方案为我自己 - 我不是特别喜欢它(*),但它的工作,所以我认为它作为临时解决方法,直到有人提供一个解决方案使用皇家路由(设置rowsource和某种make this have the desired effect)。

OK found a solution for this myself - I don't particularly like it (*), but it does work, so I regard it as a temp workaround, until somebody else provides a solution using the royal route (setting rowsource and somehow make this have the desired effect).

我检查了msdn网站,发现也可以为组合框列表填充使用自定义函数。这很容易的一部分是Access必须使用该函数的规定:只需在组合框的Source Type属性行中输入函数名,只是简单的函数名,前面没有any =在后面。

现在为不太容易的部分 - MS需要一个特定的格式的功能和具体的内容。 Mine如下:

I checked msdn site and found that it is also possible to use a self-defined function for the combobox list population. The easy part of this is the specification of the fact that Access will have to use that function: just enter the function name in the row Source Type property of the combo box, just the plain function name, without any = in front or () behind it.
Now for the less easy part - MS requires a specific format for the function and a specific content. Mine looks as follows:

Private Function customFuncName(fld As Control, id As Variant, row As Variant, col As Variant, code As Variant) As Variant
    Dim rs As Recordset
    Set rs = CurrentDb.OpenRecordset(... new query ...)

    Select Case code
        Case acLBInitialize
            customFuncName = True
        Case acLBOpen
            customFuncName = 1
        Case acLBGetRowCount
            customFuncName = rs.RecordCount
        Case acLBGetColumnWidth
            customFuncName = -1
        Case acLBGetValue            
            customFuncName = rs.GetRows(rs.RecordCount)(col, row)
    End Select

End Function

请参阅 msdn.microsoft.com rowSourceType属性和链接具体的函数代码参数

(*)因为明显的记录集开销导致性能但是自从我显示的列表是最多40行,它对我来说很好。

(*) because of the obvious recordset overhead causing performance to drop - but since the list I show is max 40 rows it works fine for me

这篇关于subform combobox rowsource update - 如何更新下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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