user2385809
user2385809

Reputation: 1005

Class property error VBA

I am getting runtine error 91: Object vriable or With block variable not set whne I run a simple class manipulation code.

Here are my classes

cTask:

Private pMile As cMile

Public Property Get Mile() As cMile
    Set Mile = pMile
End Property

Public Property Set Mile(Value As cMile)
    Set pMile = Value
End Property

Private Sub Class_Initializer()
    Set Me.Mile = New cMile
End Sub

cMile:

Private pstatus As String

Public Property Get status() As String
    status = ppstatus
End Property

Public Property Let status(Value As String)
    pstatus = Value
End Property

And the sub:

Sub testt()

    Dim ct As New cTasks

    ct.Mile.status = "compl"

    Debug.Print ct.Mile, ct.Mile.status

End Sub

The code goes from the sub to the get property in cTask. When about to execute the "End Propety" line the error pops up.

I guess something must be wrong with my classes but I don not know what. I have just recently started using classes. Any ideas?

Thank you

Upvotes: 0

Views: 377

Answers (1)

Alex K.
Alex K.

Reputation: 175926

You have a typo:

Class_Initializer()

should be

Class_Initialize()

This prevents ct's Mile from being created so accessing it raises the error you see.

ppstatus is also spelt incorrectly.

Upvotes: 1

Related Questions