Getting Error 91

2019-08-02 14:50发布

I have a general comprehension issue with classes and objects. What I'm trying to do is pretty simple but I'm getting errors. In the code example below, sometimes the line "Call tables.MethodInCTables" runs fine and sometimes it produces error 91, object not set. IN all cases, I can "see" the method in the type ahead so I know that the code recognizes the "tables" instance and "sees" MethodInCTables. But then I get the run-time error.

Sub MainSub() 
Dim tables as New CTables 
Call tables.MethodInCTables 
End Sub

----Class Module = CTables

Sub MethodInCTables()
 ...do something 
End Sub

1条回答
够拽才男人
2楼-- · 2019-08-02 15:15

You need to initialise the CTables type:

Sub MainSub()
    Dim tables As New CTables 
    Call tables.MethodInCTables
End Sub

Or:

Sub MainSub()
    Dim tables As CTables
    Set tables = New CTables
    Call tables.MethodInCTables
End Sub
查看更多
登录 后发表回答