3

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

    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")) 的引用为空。

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

4

1 回答 1

0

最需要注意的是;由于您现在正在处理“对象”而不是“变量”,因此您必须将“Set”一词放在对象变量的前面。还将 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-08-12T21:02:24.343 回答