How do you exit a program, for example if I have an Exit menu command what code do I use to exit the program?
Printable View
How do you exit a program, for example if I have an Exit menu command what code do I use to exit the program?
'Unload all forms
Public Sub UnloadFrms
Dim Form As Form
For Each Form in Forms
Unload Form
Set Form = Nothing
Next Form
End Sub
'in your unload event exit menu
Call UnloadFrms
If you have loaded any objects you should
Close them and set them to nothing as well
What HeSaidJoe described is the best way to exit, it releases all memory used by your app then common (and incorrect) way to exit is to use:
Code:End
Quote:
Originally posted by rsitogp
What HeSaidJoe described is the best way to exit, it releases all memory used by your app then common (and incorrect) way to exit is to use:
Code:End
It's not incorrect, you just should never use it alone. So with Wayne (HeSaidJoe)'s code, you can always put it after the Next.
Actually, it's the other way around. Joe's way is correct, and using End is incorrect. This is because End does not trigger any of the unload events. You can however, as Matthew Gates suggested, used End after you finish using Unload.