Application crashed

I am working on an app that is still in development. I have a main window that opens and closes just fine. Then I open another window on top of that. It works fine. If I close the overlaid window first, then close the main window the app closes properly. But if I close the main window before the overlaid window I get the “Application Crashed due to an access error” message. If I close the overlaid window from inside the Close event of the main window then it closes properly. Is there something going on whereby closing main first causes this?

Edit: I was opening the overlaid window in the main window as Var w As W_Accounts, then .Show. So I created a global property (in App) for the window. Then in the main window opened it with App.AccountsWindow As W_Account. Took out the closing in the main closing event and now closing the main first closes everything properly.

just be sure if you close this window set the reference App.AccountsWindow = nil

use System.DebugLog CurrentMethodName in methods/events to understand the app flow.

Thanks Markus, will check it out.