macro to end or quit another macro

smiler44

Registered User.
Local time
Today, 14:53
Joined
Jul 15, 2008
Messages
678
Once a macro is running is there a way using code to stop it running until it is next called?

smiler44
 
We will need a lot more details about what your macro is doing.

Without knowing more about what your macros does, this may be a situation where a Macro just is not powerful enough. You might
consider using VBA code.
 
Hey Boyd ...

>> Macro just is not powerful enough. <<

Since this was posted in Excel ... I am thinking the OP is meaning a VBA prodedure ... not an Access Macro ... :)
 
Hey smiler44 ...

Like Boyd says ... we need a lot more info ... but ... I will take a stab at it anyway. First off, note that VBA is single threaded, so it can only do one thing at a time. With that, you will probably need to make use of a module variable, and the DoEvents command .... something like this ...

Code:
Option Explicit
 
Private blStopProcess As Boolean
 
'Code behind a command button named 'btnStopProcess'
Public Sub btnStopProcess_Click()
    blStopProcess = True
End Sub
 
'Code the needs to be interrupted.
Public Sub StoppableProces()
 
    Dim x As Integer
 
    Do Until blStopProcess = True
 
        If x <= 32767
            x = x + 1
        Else
            x = 0
        End If
 
        DoEvents
 
    Loop
 
    blStopProcess = False
    MsgBox "Wooo Hooo ... Someone hit the button!"
 
End Sub


So ... when you Click on the button, the click goes into a "que" since the processor is busy with the Do..Loop ... but when the DoEvents is executed, Access basically halts the code, "releases" the processor to perform a pending event, like the Click that is qued, which then sets the blStopProcess to True ... the code calling the DoEvents is then returned to, and the Do..Loop is exited and the variable reset to false and the message is displayed ...

.....

Hope that helps!
 
The code I'm using I found via Google but I am unable to work out how to stop the code once it starts running. Sorry I thought the answer would be easy

A solution I came up with is to have an if statement in the onetime macro
such as:

If Sheet1.CheckBox7.Value = True Then
Exit Sub
Else
application.ontime bla bla bla
End Sub


what I'm using is

Code:
Option Explicit
 
Sub OnTimeMacro()
    Application.OnTime Now + TimeValue("00:00:01"), _
    "RunEveryMinute"
 End Sub
 
Sub RunEveryMinute()
    With Worksheets(1)
         'Range("A1").Value = Format(Now, "hh:mm:ss")
         Sheet1.TextBox1.Text = Format(Now, "hh:mm")
    End With
    Call OnTimeMacro
End Sub
 
Hey Boyd ...

>> Macro just is not powerful enough. <<

Since this was posted in Excel ... I am thinking the OP is meaning a VBA prodedure ... not an Access Macro ... :)

Brent,
My bad . You are correct! Thanks for pointing that out.
 

Users who are viewing this thread

Back
Top Bottom