andyb7901
asked on
MS Access VBA - Exiting SUB from another form
Hi,
I have a form which loaded from a module. When I press the cancle button on my form is there anyway to exit the sub in which the code is currently running?
Thanks
I have a form which loaded from a module. When I press the cancle button on my form is there anyway to exit the sub in which the code is currently running?
Thanks
If you have a looping procedure which takes a long time and you want to be able to stop it, you will need to have it test a variable each time that it goes through the loop and to have DoEvents in the loop to allow the variable to be updated.
Your Cancel button would change the value of the variable. The (VB6) snippet illustrates
Your Cancel button would change the value of the variable. The (VB6) snippet illustrates
Option Explicit
Dim bStop As Boolean
Private Sub Command1_Click()
Do
Text1.Text = (Val(Text1.Text) + 1) Mod 30000
DoEvents
If bStop Then
bStop = False
Exit Sub
End If
Loop
End Sub
Private Sub Command2_Click()
bStop = True
End Sub
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
DoCmd.Close
the form will close, and you will 'return' to the sub.
Is that what you meant?