You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Access中RowSourceType自定义函数传入常量2的作用疑问

Access自定义列表函数中未文档化常量2的作用

我在学习Access教材示例时,发现可通过控件的RowSourceType属性调用自定义函数填充组合框或列表框,这类函数需要接收Access传入的特定常量。但运行指定自定义函数时,即时窗口输出显示Access传入了一个未在官方文档及Access.Constants中找到的常量2,特此询问该常量的作用。

自定义函数代码

Function listEndDates(fld As Control, id As Variant, row As Variant, col As Variant, code As Variant) As Variant
    Debug.Print code 'I inserted this so I could see what constants Access was giving the function
    Dim integerOffset As Integer
    
    Select Case code
        Case acLBInitialize
            listEndDates = True
        Case acLBOpen
            listEndDates = Timer
        Case acLBGetRowCount
            listEndDates = 11
        Case acLBGetColumnCount
            listEndDates = 1
        Case acLBGetColumnWidth
            listEndDates = -1
        Case acLBGetValue
            integerOffset = Abs((8 - Weekday(Now)) Mod 7)
            listEndDates = Format(((Now() + integerOffset) - 35) _
       + 7 * row, "MM/DD/YYYY")
    End Select
    
End Function

即时窗口输出

0 acLBInitialize

 2
 1 acLBOpen
 4 acLBGetColumnCount
 5 acLBGetColumnWidth
 5 acLBGetColumnWidth
 3 acLBGetRowCount

 6 acLBGetValue
 7 acLBGetFormat

常量2的作用

这个未文档化的常量2对应的是**acLBClose**(列表框关闭通知),它是Access在列表框/组合框销毁或数据源刷新时传入的信号,用于让自定义函数执行清理操作,比如释放占用的资源、关闭临时记录集等。

你的代码里没有处理这个常量分支,所以即时窗口只输出了数字2,没有对应的常量名称。如果需要处理该逻辑,可以在Select Case中添加如下分支:

Case 2 ' acLBClose
    ' 示例:释放资源或执行清理操作
    listEndDates = True

需要注意的是,该常量属于Access未公开的内部常量,官方文档不会提及,不同版本的Access可能存在行为差异,使用时需谨慎测试。

内容的提问来源于stack exchange,提问作者youarethemusic

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 06:46:09