OnTime no workie in Userform

R

rci

Hi all...

the OnTime function does not work inside userform code... in the sense that
the sub that it calls can't be run in the Userform code.

The reason why I need to have it work otherwise, or to find an alternative,
is that I need to cause a button (on a userform) to become invisible after a few
seconds (while not impairing normal program funciton in the meantime).

I can cause OnTime to launch a sub in standard module code... but userform
objects are apparently invisible to code running there.

Suggestions?

Thanks all!

MP
 
T

Tom Ogilvy

You probably just need to make the procedure in the Userform that you want
Ontime to call to be public.

Public Sub ProcedureName()

End Sub

then perhaps call it with

Application.Ontime Now + Timevalue("0:0:15"), "Userform1.ProcedureName"

Where userform1 would be the name of the userform.
 
R

rci

Hi Tom,

thanks.... but the problem is the same... here is the code involved:


the DammitButton in inside Frame1 on the userform "S2pViewer" -



Private Sub DirListBox_DblClick(ByVal Cancel As MSForms.ReturnBoolean)

DammitButton.Visible = True
Application.OnTime Now + TimeValue("0:0:4"), "S2pViewer.DammitClear"

End Sub

Public Sub DammitClear()
DammitButton.Visible = False
End Sub



The error message is that the macro S2pViewer.DammitClear cannot be found.


Excel 2002


Thx,

MP





: You probably just need to make the procedure in the Userform that you want
: Ontime to call to be public.

: Public Sub ProcedureName()

: End Sub

: then perhaps call it with

: Application.Ontime Now + Timevalue("0:0:15"), "Userform1.ProcedureName"

: Where userform1 would be the name of the userform.

: --
: Regards,
: Tom Ogilvy

: :>
:> Hi all...
:>
:> the OnTime function does not work inside userform code... in the sense
: that
:> the sub that it calls can't be run in the Userform code.
:>
:> The reason why I need to have it work otherwise, or to find an
: alternative,
:> is that I need to cause a button (on a userform) to become invisible after
: a few
:> seconds (while not impairing normal program funciton in the meantime).
:>
:> I can cause OnTime to launch a sub in standard module code... but userform
:> objects are apparently invisible to code running there.
:>
:> Suggestions?
:>
:> Thanks all!
:>
:> MP
 
T

Tom Ogilvy

I didn't get the error you describe unless I dropped the userform before 4
seconds elapsed.

However, it didn't seem to run. If I put the Dammitclear procedure in a
general module, it ran for me.

in the S2pViewer module:

Private Sub DirListBox_DblClick(ByVal Cancel As MSForms.ReturnBoolean)

DammitButton.Visible = True
Application.OnTime Now + TimeValue("0:0:4"), "DammitClear"

End Sub


In a general module:

Public Sub DammitClear()
MsgBox "I ran"
S2pViewer.Frame1.DammitButton.Visible = False
End Sub
 
R

rci

Ah... this works.

Thanks again, Tom.



: I didn't get the error you describe unless I dropped the userform before 4
: seconds elapsed.

: However, it didn't seem to run. If I put the Dammitclear procedure in a
: general module, it ran for me.


: in the S2pViewer module:

: Private Sub DirListBox_DblClick(ByVal Cancel As MSForms.ReturnBoolean)

: DammitButton.Visible = True
: Application.OnTime Now + TimeValue("0:0:4"), "DammitClear"

: End Sub


: In a general module:

: Public Sub DammitClear()
: MsgBox "I ran"
: S2pViewer.Frame1.DammitButton.Visible = False
: End Sub

: --
: regards,
: Tom Ogilvy

: :>
:> Hi Tom,
:>
:> thanks.... but the problem is the same... here is the code involved:
:>
:>
:> the DammitButton in inside Frame1 on the userform "S2pViewer" -
:>
:>
:>
:> Private Sub DirListBox_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
:>
:> DammitButton.Visible = True
:> Application.OnTime Now + TimeValue("0:0:4"), "S2pViewer.DammitClear"
:>
:> End Sub
:>
:> Public Sub DammitClear()
:> DammitButton.Visible = False
:> End Sub
:>
:>
:>
:> The error message is that the macro S2pViewer.DammitClear cannot be found.
:>
:>
:> Excel 2002
:>
:>
:> Thx,
:>
:> MP
:>
:>
:>
:>
:>
:> : You probably just need to make the procedure in the Userform that you
: want
:> : Ontime to call to be public.
:>
:> : Public Sub ProcedureName()
:>
:> : End Sub
:>
:> : then perhaps call it with
:>
:> : Application.Ontime Now + Timevalue("0:0:15"), "Userform1.ProcedureName"
:>
:> : Where userform1 would be the name of the userform.
:>
:> : --
:> : Regards,
:> : Tom Ogilvy
:>
:> : :> :>
:> :> Hi all...
:> :>
:> :> the OnTime function does not work inside userform code... in the sense
:> : that
:> :> the sub that it calls can't be run in the Userform code.
:> :>
:> :> The reason why I need to have it work otherwise, or to find an
:> : alternative,
:> :> is that I need to cause a button (on a userform) to become invisible
: after
:> : a few
:> :> seconds (while not impairing normal program funciton in the meantime).
:> :>
:> :> I can cause OnTime to launch a sub in standard module code... but
: userform
:> :> objects are apparently invisible to code running there.
:> :>
:> :> Suggestions?
:> :>
:> :> Thanks all!
:> :>
:> :> MP
:>
:>
 
Top