Help - userform stuck in memory, won't unload

ironfelix717

New Member
Joined
Jul 8, 2016
Messages
14
Hi,

I have had this issue before. I had once thought it was a bug with the QueryClose event class.

See my post here: https://www.excelforum.com/excel-pr...-form-will-not-unload-vbqueryclose-event.html

My textbox value in my topmost form is not clearing... because the form is not unloading. DESPITE me explicitly telling the form to unload and hide regardless of where i put that code.

When the first form opens, it always re-sets the cell value to "1000" which is correct. However after editing the textbox in the second form, reloading the entire process no longer allows the textbox in form 2 to display "1000". It shows what was last entered... because its hanging in memory.


In my thread from some months ago (above), it was temporarily solved via setting the form object to nothing.

However, I have had no success this time.

Some other points:
I need two forms - no negotiating there, sorry.

Prefer to have the query close event close the form instead of a dedicated button. I want the X button to close the form.


Any help is greatly appreciated. Been on this for hours -_-

Thank you
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
xlnitwit gave you this advice:

I don't think it's a bug, just a flaw in your code logic. Your QueryClose code cancels the userform close and loads the exit form, at which point the QueryClose code is still running but paused waiting for the exit form to either hide or unload and return control. Your exit form tries to unload the Quote form but it can't because that form is still running code and has cancelled the close.

In my opinion you should redesign the flow completely. The Quote form should be responsible for loading and unloading the exit form. The exit form should have three properties, which return the user's choice, and should only hide itself at the end. The quote form then reads the response before unloading the exit form and proceeding as appropriate, based on the user choice.

My thoughts
There are times when we all use workarounds to overcome problems.
Your issue was temporarily solved via "setting the form object to nothing" - which is more brute force than workaround
Unless dealt with in the correct way, a problem often reappears later and may even result in a dfferent obscure issue which is difficult to trace.
Excel (sometimes frustratingly) works the way it does and IMHO xlnitwits's advice is the way to go.

I need two forms - no negotiating there, sorry
- can you explain why you "need" two forms

How about the illusion of 2 forms
- creating all the objects
- hiding some becomes form1
- revealling those and hiding the rest becomes form2
- resize the userform (etc) if needed

Try this
- create a simple user form with 1 toggle button and 4 textboxes
- add the code below to the userform module
- now show the form and click on the button a few times
Code:
Private Sub ToggleButton1_Click()

If ToggleButton1.Value = True Then
    ToggleButton1.Caption = "Form2"
    UserForm1.Width = "400"
    TextBox1.Visible = True
    TextBox2.Visible = True
    TextBox3.Visible = False
    TextBox4.Visible = False
Else
    ToggleButton1.Caption = "Form1"
    UserForm1.Width = "500"
    TextBox1.Visible = False
    TextBox2.Visible = False
    TextBox3.Visible = True
    TextBox4.Visible = True
End If

End Sub
 
Last edited:
Upvote 0
Cross posted
https://www.excelforum.com/excel-pr...to-unload-top-form-correctly.html#post4958710

While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0
....

Prefer to have the query close event close the form instead of a dedicated button. I want the X button to close the form.


Any help is greatly appreciated. Been on this for hours -_-

Thank you
As I said in one of the other threads, there is no need for any code in the QueryClose event. The form will close just fine if that event is removed from the userform's code module. The QueryClose event is needed if you want to avoid the corner X. If you want corner X to close the form, QueryClose is not needed.
 
Upvote 0
Yongle:

I need two forms because.... why can't i. This is visual basic. We are developing a user interface. It is quite common for a user interface in software to have multiple forms overlayed. My application is complex and cramming every input on one userform is just... silly. I humbly thank you for your solution, but its not feasible in my form.

mikerickerson,

Thank you for reiterating.


Thanks to all.


This thread should be closed and the relevant crossthread is here with solution:


https://www.excelforum.com/excel-pr...to-unload-top-form-correctly.html#post4958780


Thanks to all
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top