Best Way To Quit An Application - Newbie question

  • Thread starter Thread starter Richard Harris
  • Start date Start date
R

Richard Harris

I have a form that opens a password checking form. Can anyone tell me how
to quit the application half way through a Sub without running the rest of
the code if the user enters the wrong password.

I've tried application.exit() but that still runs through the rest of my
code.

..
 
* "Richard Harris said:
I have a form that opens a password checking form. Can anyone tell me how
to quit the application half way through a Sub without running the rest of
the code if the user enters the wrong password.

Close the form (maybe you will have to set a Boolean variable to
indicate that other code should not be executed). If you post more
details on your code, an accurate answer would be possible.
I've tried application.exit() but that still runs through the rest of my
code.

I wouldn't use that.
 
I have a form that opens a password checking form. Can anyone tell me
how to quit the application half way through a Sub without running the
rest of the code if the user enters the wrong password.

I've tried application.exit() but that still runs through the rest of
my code.

Right after you find the problem use Exit Sub to bail out of that sub.
Here is a trick: Don't use subs. Use functions instead.

My password checker is a function that returns a boolean value. If the
user ID is not valid I use Return False to get me the heck out. If the
password supplied does not match the password for the user Return False
gets me out there too. Of course you need Return True at the bootom of
the function to signal success.

You are likely in a KeyPress event when checking the password. Use
Me.Close() to end your form and call Exit Sub right after so that no more
code gets executed.
 
Back
Top