0

I have created in VBA class that contains a collection of objects. When I try to add objects via a method that I have created I'm getting:

"438 - object dosen't support this property or method vba"

even if the method exist on my class.

myCronCol is an instance of the CronCol class defined here:

Private Sub Class_Initialize()
    Call InstanceProfiler.AddInstance(Me)

   Set myCol = New Collection


 End Sub

Private Sub Class_Terminate()
    On Error GoTo Class_Terminate_Err
    DoEvents
    Call InstanceProfiler.RemoveInstance(Me)
    Exit Sub
Class_Terminate_Err:
    Call Log.add(e_ltError,  "Class_Terminate", Err.Description)
    Resume Next
End Sub

Public Sub addElement(ByRef cronElement As ClsCron)

    myCol.add cronElement

End Sub

myCol is declared in a modul as public variable and is being initialized when the master object is initialized.

Dim myCol As Collection
...


Public Sub addElement(ByVal cronElement As ClsCron)

    myCol.add cronElement

End Sub


Dim Cron as ClsCron
    Set Cron =  new ClsCron
    'some constructors
    Cron.Init("abba","banana")

Here the error apears:

 myCronCol.addElement (Cron)

What I'm doing wrong? :-(

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
SocketM
  • 564
  • 1
  • 19
  • 34
  • 1
    what is `myCronCol` and where is it declared? Can you provide a [mcve]? – David Zemens Jun 21 '19 at 13:52
  • 4
    probably get rid of the parentheses around `(Cron)`, because that class won't have a default property/method. The parens are forcing an evaluation, which is likely raising that error because `Cron` does not implement this (default) property or method. – David Zemens Jun 21 '19 at 13:54
  • 1
    see [here](https://stackoverflow.com/questions/56692769/vba-usage-of-parentheses-for-a-method#comment99952066_56692769) and [here](https://stackoverflow.com/questions/10262186/vb6-pass-by-value-and-pass-by-reference/10262247#10262247) maybe. – David Zemens Jun 21 '19 at 13:55
  • @David Zemens myCronCol is an instance of a collection class that I have created – SocketM Jun 21 '19 at 14:02

0 Answers0