Declaring a new object (1 Viewer)

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 16:51
Joined
Feb 28, 2001
Messages
27,001
I am playing around with converting some old code of mine to be a class object so that I can learn a little more about class object manipulation. The object code (and in fact everything in the DB set up for testing) compiles without error, but I get the dreaded "Error 91 - Object variable or With block variable not set." when I try to use it.

The class module IS declared as such. It shows up in my navigation panel as a class module, not an ordinary or forms module. (See included image)

In the form I'm using to test this, in the form's general declaration area I have:
Code:
Dim Prs As ParserObj            'the object of testing

The form is unbound so there wouldn't be a Form_Current event. Therefore, in the Form_Load routine, I attempt to create the new class object. That is when I get the error on the "Set" line. I can single-step past the offending line and the debugger enters the ParserObj "Initialize" event routine but when it comes back it hasn't been initiated because I keep getting that error.

Code:
    Set Prs = New ParserObj     'create the parser object

So... what's up with this? What do I look for? This in on Win10 64-bit and Access 2010 32-bit. Resources are NOT a problem.

ClassInList.png
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 21:51
Joined
Jul 9, 2003
Messages
16,245
I can only speak for my own personal class module;- "clsCallCalled" and I'm not 100% sure I understand your question, I get the feeling I am missing something.

I have a class module called "clsCallCalled" and I use the following code in a Form to initiate the class:-

Code:
'This is The Declarations Section
'*******************************************************************************************************
'***** Object (Class) variable to keep the Class open and available for the life of this Form **********
'*******************************************************************************************************
Private CallCalled As clsCallCalled 'this is set in the Forms Open Event

''''############## ---------------- Form Control Events ----------------- ########
Private Sub Form_Open(Cancel As Integer)
'Stop the Form Opening in the Nav Pane
'https://www.access-programmers.co.uk/forums/showthread.php?t=281839
'https://msdn.microsoft.com/en-us/library/office/ff196795.aspx
    Dim strCurrentName As String
    strCurrentName = Application.CurrentObjectName
    
    If strCurrentName = Me.Name Then
        Cancel = True
        Exit Sub
    End If

'================== This Code is Generic to any Form using the clsCallCalled ===========================
Set CallCalled = New clsCallCalled 'Set the Class (Object) in the declarations section of this Form
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 16:51
Joined
Feb 28, 2001
Messages
27,001
I use a DIm rather than a Private to declare the class object variable, which is the only thing different that I see from your example. But then when I attempt to create the object with the New (like you do) it tells me that something wasn't set. The class module is there and should be something I can create with New. My problem, therefore, is that something is blocking creation of this object. Yet nothing shows an error during compilation and practically the first thing I do in the Form_Load routine is to create the object. No other code has run yet to have gotten in the way. I am wondering what step I have left out because from what I have read, I've done everything I'm supposed to do.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 21:51
Joined
Jul 9, 2003
Messages
16,245
I'm wondering if you got the common problem I have, in that you can't see the wood for the trees.

I'm reasonably sure that error message is also caused by missing End Ifs, missing end with, and for next loops not being closed out properly.

Also I sometimes forget to use the SET word for setting object variables and I think you'll get that self same error message if you do that....
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 17:51
Joined
May 21, 2018
Messages
8,463
My guess without seeing ,is a problem in the class module. In the Tools, Options, General tab select in the Error Trapping "Break In Class Module". See if you now break in the class module. For debugging get used to switching back and forth between breaking in the class and breaking in unhandled errors. If not what will happen is that the error show in the form but the class is never instantiated.

Do you have code in the class_initialize event. Although DIM will default to private in scope, it is more specific to use dim.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 16:51
Joined
Feb 28, 2001
Messages
27,001
I have some DIM statements for variables intended to be "local" for the class code but available through LET/GET PROPERTY routines.

The class Initialize event asserts values (setting 0 or "" or FALSE) in the DIM'd variables. For the lifetime of my object, there is a Dictionary object created by the INITIALIZE routine and destroyed by the Terminate routine.

"If not what will happen is that the error show in the form but the class is never instantiated." That sounds productive because I can single-step and see some of the Initialize code but then it just dies. So it MIGHT be a failure to create a dictionary object in the context of the class object.

Uncle G: If I had open "End If" or "End With" or "Do/Loop" cases, it wouldn't compile.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 17:51
Joined
May 21, 2018
Messages
8,463
My guess would be no new keyword on the dictionary object instantiation
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 16:51
Joined
Feb 28, 2001
Messages
27,001
Actually, I have gotten things moving again. I moved the dictionary creation step to later in the routine, but what I moved DID have a "New" in the right place. The whole project had been compiled more than once. When I tell people what happened next, they stare at me like I've grown another head, but it isn't the first time I've seen this. I put a breakpoint in the Initialize routine and single-stepped my way through it - with no errors. Stopped it, killed all breakpoints, and tested again - and it worked. It's almost like it wanted me to single-step my way through the code once (to show it the way?), then started working. It has certainly got ME bamfoozled. But now I am debugging the main routine and all that is left of it is the tests for end conditions to avoid the "non-finite automaton" case. You put me on the right track, though, MajP, in pointing out that the Error 91 might not have been for MY object. It might well have been for the dictionary object that I use.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 16:51
Joined
Feb 28, 2001
Messages
27,001
UPDATE: I've got everything going except error handling. I think I'll start a separate thread on that one. MajP, I think you were right about the error being something else.
 

Users who are viewing this thread

Top Bottom