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
formASD.Show

and in the formASD I'm just using

Me.Hide

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?

WC
LVL 18
Cory VandenbergSenior Risk ManagerAsked:
Who is Participating?
 
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
frm.Show
Unload frm
set frm = nothing
0
 
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.

Cheers,
WC
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.