我有一个函数,我想根据字符串参数返回不同的列表框。 这是函数:
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’:未设置对象变量或 With block 变量”。当我使用调试器时,它告诉我对 list61(Me.list61, Me.Controls("List61")) 的引用为空。
有人知道如何解决这个问题吗?任何帮助我将不胜感激。
最佳答案
最重要的是要注意;因为你现在处理的是“对象”而不是“变量”,你必须在对象变量前面加上“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
https://stackoverflow.com/questions/17365834/