Stop A Procedure

R

RKM solutions

Hi guys,

Im currently looking for a function that will stop a procedure if the same
procedure is recalled during its execution.

To explain, the diary system which im developing requires a btn to process
tomorrows appointments.. when pressed the btn changes the date, then a
lengthy looping procedure runs the actions based on that date.

My problem is that should the user wish to search forward through dates
using this feature I need to prevent every date that is bypassed calling the
procedure.

For example
Btnclick()

'tmrws date
ChangeDate 1

'if running cancel last occurrence
"cancel procedure"(populateApps)

PopulateApps
end sub

Hope that this makes sense
Cheers
Rkm
 
J

Jack Leach

You can create a variable at module level and flag it on/off at the beginning
and end of the procedure:

Option Compare Database
Option Explicit

Private pProcedureRunning As Boolean

Private Sub YourProcedure()
On Error Goto Error_Proc

If pProcedureRunning = True Then
Goto Exit_Proc
Else
pProcedureRunning = True
End If

....
....

pProcedureRunning = False
Exit_Proc:
Exit Sub
Error_Proc:
'Error handler
Resume Exit_Proc
End Sub


hth
--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
J

Jack Leach

In fact, there's a couple of key procedures I use sometimes where I don't
want my users accessing at the same time (reads/writes to property tables),
and I use a global property in exactly the same way. The key procedure
itself is 'wrapped' by a verification function... if noone's in it, set the
property to true and run with it, otherwise run a stall-loop for a second or
two and try again. Then on the way out of the wrapper function, set the
property back to false.

If you're looking to do this in the scope of the entire project, but are not
sure about how to use properties, MZTools has a feature to convert a public
variable to a property (public variables are not reliable for this sort of
thing, apparently).

It seems to work pretty well, though admittedly I don't think I've every had
a case yet where two people are trying to edit the same table/record at the
same time. It's a nice safegaurd though.
--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top