Results 1 to 3 of 3

Thread: [RESOLVED] Runtime error 424 when referring to class method

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2020
    Posts
    4

    Resolved [RESOLVED] Runtime error 424 when referring to class method

    I have created a simple class, cTimeUp. I want to call a function in the class every n seconds using a timer, TimerTimeUp on the form.

    When I call the class methods from the form they work, when they are called from the timer I get error 424.

    Also intelligence does not see the class objects when typing in Sub TimerTimeUp_Timer(), which is consistent with "Object required".

    I have searched for a solution without success but I think the cause is to do with scope? I would be grateful for suggestions.

    Private Sub Form_Load()
    TimerTimeUp.Interval = 1000
    TimerTimeUp.Enabled = True
    Dim My As cTimeUp
    Set My = New cTimeUp
    My.SetTime (5)
    MsgBox My.IsTimeUp ' This returns True as it should
    End Sub


    Private Sub TimerTimeUp_Timer()
    MsgBox My.IsTimeUp ' This gives run time error 424 when the timer fires
    If My.IsTimeUp Then
    ' Time is up
    Debug.Print "Time up " & " at "; Now()
    Else
    Debug.Print Now()
    End If
    End Sub

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Runtime error 424 when referring to class method

    as my is dimensioned within the form load event, it is out of scope for the timer procedure, you should dimension it at module level or globally for all modules

    you should move the Dim My As cTimeUp line to the top of the code module for the form (in the general section), or move it to the top of a module as public
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2020
    Posts
    4

    Re: [RESOLVED] Runtime error 424 when referring to class method

    Thank you so much, its now working. I missed the obvious while looking for a complicated solution to a simple problem!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width