Unload Me is causing an error which closes all forms

I have a form which is initialized and shown by code from a button on another form.  When the "embedded" form is closed, the original form is also closed and unloaded.  If I just Hide the "embedded" form, there is no issue.

Now, to get around this, in the main form I am using

Unload formASD

and in the formASD I'm just using


That solution is fine.  I guess I am just curious if the behavior I am experiencing when using Unload Me on the embedded form is normal or not?

LVL 18
Cory VandenbergSenior Risk ManagerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rory ArchibaldCommented:
No it's not normal behaviour. It's not good practice to use the default instance of the userform though - you should declare a variable and use that instead (and therefore use Hide when closing the form and have the calling form unload the called form afterwards. So for example:

Dim frm as formASD
set frm = New formASD
Unload frm
set frm = nothing

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cory VandenbergSenior Risk ManagerAuthor Commented:
Thanks for the tip Rory.  Always looking for best practices.

The trick was, someone could load the form once, Cancel, then load it again with a different location (form list files in a folder designated on the main form).

Thus I need to Unload the formASD before I Show it, just in case it's not the first time.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.