【问题标题】:How do I set a variable to one of my form's listboxes in vba(access)?如何在 vba(access) 中将变量设置为我的表单列表框之一?
【发布时间】:2013-06-28 13:27:52
【问题描述】:

我有一个函数,我想根据字符串参数返回不同的列表框。 这是函数:

    Here is the function:
Private Function returnList(name As String) As AccessObject
If name = "app" Then
    returnList = Me.Controls("List61")
    'I have also tried the following: 
    'returnList = Me.List61, returnList = Forms![Daily Reports]![List61]
ElseIf name = "lpar" Then
'..several more cases
End If
End Function

每当我尝试调用它时,都会收到“运行时错误 '91':对象变量或未设置块变量”。当我使用调试器时,它告诉我对 list61(Me.list61, Me.Controls("List61")) 的引用为空。

有人知道如何解决这个问题吗?任何帮助我都会非常感激。

【问题讨论】:

    标签: ms-access vba


    【解决方案1】:

    最重要的是要注意;由于您现在处理的是“对象”而不是“变量”,因此您必须将“设置”一词放在对象变量的前面。还要将 AccessObject 类型更改为 ListBox。

    Private Function returnList(name As String) As ListBox
    If name = "app" Then
        Set returnList = Me.Controls("List61")
        'I have also tried the following:
        'returnList = Me.List61, returnList = Forms![Daily Reports]![List61]
    ElseIf name = "lpar" Then
    '..several more cases
    End If
    End Function
    

    【讨论】:

      猜你喜欢
      • 2015-12-11
      • 1970-01-01
      • 2014-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-09
      • 2014-09-07
      • 1970-01-01
      相关资源
      最近更新 更多