+ Reply to Thread
Results 1 to 10 of 10

VBA Form Not Unloading / Memory Stuck - How to unload top form correctly

  1. #1
    Forum Contributor
    Join Date
    08-22-2017
    Location
    USA
    MS-Off Ver
    2016 WINDOWS and MAC
    Posts
    294

    VBA Form Not Unloading / Memory Stuck - How to unload top form correctly

    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-pro...ose-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.

    You will see in the attached example that my form never unloads. When the first form opens, it always re-sets the cell value to "1000" which is correct. However, youll find that 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


    *Also posted here:

    https://www.mrexcel.com/forum/excel-...nt-unload.html
    Attached Files Attached Files
    Last edited by ironfelix717; 08-20-2018 at 10:10 PM.

  2. #2
    Forum Contributor
    Join Date
    08-22-2017
    Location
    USA
    MS-Off Ver
    2016 WINDOWS and MAC
    Posts
    294

    Re: VBA Form Not Unloading / Memory Stuck - How to unload top form correctly

    Further debugging... I was able to fix the attached sheet. However MY personal workbook is not fixed. I simply removed Cancel = True in the above workbook. See attached....




    In my actual workbook this is the culprit....

    Please Login or Register  to view this content.
    Anytime i set a control in the userform to a value on the spreadsheet in the query close event, whether that is directly hardcoded (above) or through a called function, the problem exists.

    I can reset the form's memory by opening the second from and going into VbEditor and hitting the reset button. But that is precisely the only way I can reset the form.

    ...Back to my original statement. This IS a bug. And an annoying one that after 4 hours I can't seem to fix. This is wasting my time.

    Thanks
    Attached Files Attached Files
    Last edited by ironfelix717; 08-18-2018 at 10:06 PM.

  3. #3
    Forum Contributor
    Join Date
    08-22-2017
    Location
    USA
    MS-Off Ver
    2016 WINDOWS and MAC
    Posts
    294

    Re: VBA Form Not Unloading / Memory Stuck - How to unload top form correctly

    Hi,

    So ive found a way to fix the problem, but I still can't wrap my head around why the original problem occurs.

    Looking at the code below...

    Please Login or Register  to view this content.

    This line causes the form to not unload after exiting BOTH forms. The "add_charges" form first then the main form.

    Please Login or Register  to view this content.
    Because I want the second userform (add_charges) to retain its value on exit, the initialize event for this second form calls this...

    Please Login or Register  to view this content.
    No suprises there. its the inverse operation to the above.

    Now, interestingly, if I change the cell in my second form's query_close event to ANYTHING except what is being pulled in in the userform initialize event, the memory doesn't hang... but then i dont have what I am trying to achieve.

    This led me to believe, eventually that the second forms initialize event was acting up...

    I change the initialize event to "Userform_Activate" and it is now unloading properly.


    I still say this is a bug. Excel isn't unloading/loading forms properly!

    Thanks... will await responses/thoughts/comments prior to solving thread. Technically... remains "unsolved"

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: VBA Form Not Unloading / Memory Stuck - How to unload top form correctly

    If you change the QueryClose routine in the second userform, Add_Charges, to
    Please Login or Register  to view this content.
    It fixes the problem. The extra lines
    Please Login or Register  to view this content.
    were causing the problem. And those lines are unneeded since the form is already on the way to being unloaded without that code.
    Also, I would remove all the code that you have in Edit_Charges QueryClose event. Again, there is no need to code for the hiding/unloading of a form in its own QueryClose event.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Forum Contributor
    Join Date
    08-22-2017
    Location
    USA
    MS-Off Ver
    2016 WINDOWS and MAC
    Posts
    294

    Re: VBA Form Not Unloading / Memory Stuck - How to unload top form correctly

    mikerickson,
    I appreciate your reply and investigation to this.


    That is true for that spreadsheet. Its a poor example. Why? I dont know. Its the same process as my main workbook.

    But I just tested your theories in a faulty version of my actual workbook which I saved before I made my solutions above...

    No avail. Removing the redundant code does not fix the issue...
    Thanks

  6. #6
    Forum Contributor
    Join Date
    08-22-2017
    Location
    USA
    MS-Off Ver
    2016 WINDOWS and MAC
    Posts
    294

    Re: VBA Form Not Unloading / Memory Stuck - How to unload top form correctly

    so I have repeatedly tried to re-produce this issue in a sanitized workbook to upload, but it is somehow working when I sanitize the workbook.

    I don't understand what is going on with that workbook.

    I will attempt to try and get a sanatized version of the exact workbook to display the exact problem sometime.

    thanks

  7. #7
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: VBA Form Not Unloading / Memory Stuck - How to unload top form correctly

    I've mocked up something that might help you.
    In this example, the first userform (frmAlpha) takes a delimited string, from TextBox1, and "links" it to the two cells A1 and B1.
    The sub form allows the user to enter the data into two textboxes, Textbox2 and TextBox3, and returns a delimited string the TextBox1 of the first form.

    I've also included the same functionality in a single userform with a Multipage control. This approach eliminates the problems that come when piling one userform on a sub userform and keeping who is what straight. The multipage approach puts everthing in a single userform
    Attached Files Attached Files

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,466

    Re: VBA Form Not Unloading / Memory Stuck - How to unload top form correctly

    Rule 08: Cross-posting Without Telling Us

    Your post does not comply with Rule 8 of our Forum RULES. Do not cross-post your question on multiple forums without telling us about your threads on other forums.

    Post a link to any other forums where you have asked the same question. If you have fewer than 10 posts here, you will not be able to post a link, but you must still tell us where else you have asked the question.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).

    If you have less than 10 posts, do not try to copy and paste the link. Instead, type the link out in your thread.

    No further help to be offered, please, until the OP has complied with this request.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  9. #9
    Forum Contributor
    Join Date
    08-22-2017
    Location
    USA
    MS-Off Ver
    2016 WINDOWS and MAC
    Posts
    294

    Re: VBA Form Not Unloading / Memory Stuck - How to unload top form correctly

    mikerickerson,

    thanks a lot for the example. However, I must say the problem with this approach is that is hides the main userform (alpha in your example). I prefer to have the main form open and sub form over top.

    Nonetheless, I really like the multi-page approach you did and i intend to use it in the future for a UI mechanism!

    Thank you

  10. #10
    Forum Contributor
    Join Date
    08-22-2017
    Location
    USA
    MS-Off Ver
    2016 WINDOWS and MAC
    Posts
    294

    Re: VBA Form Not Unloading / Memory Stuck - How to unload top form correctly

    FINAL THOUGHTS:

    It appears there is no way for me to reproduce the issue I was having with the form not unloading. Using the code recommendations here (fixing my bugs), I still do not resolve the issue. I have saved a copy of that workbook for future analysis on a rainy day.

    Ultimately, I have solved this issue by using
    Please Login or Register  to view this content.
    in the sub-form to import the spreadsheet values, versus
    Please Login or Register  to view this content.
    , as seen in post #3 above.


    Thank you

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Unloading a Form
    By VBA Fun in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-25-2019, 12:52 AM
  2. Unloading Form Throwing Error
    By Bensley in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-08-2018, 09:40 AM
  3. How to show/hide/unload form when form name is a string variable?
    By achmidt in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-13-2012, 06:21 PM
  4. Unloading Form on clear contents
    By reggie1000 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-20-2009, 11:10 AM
  5. Lose cursor after unloading form
    By andreco in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-12-2008, 03:39 PM
  6. [SOLVED] Strange issue freezing parent form when unloading a child form
    By Stefano Gatto in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-11-2005, 12:45 PM
  7. Unloading a form using the ESC key
    By johncassell in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-16-2005, 01:19 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1