+ Reply to Thread
Results 1 to 10 of 10

Closing form doesn't stop program

  1. #1
    Forum Contributor
    Join Date
    10-12-2018
    Location
    Leesburg, FL
    MS-Off Ver
    2013
    Posts
    113

    Closing form doesn't stop program

    I have a form that opens a file and then makes some changes and saves it. The form has an exit button which unloads the form. However, this doesn't seem to release the newly saved file. When I exit the form via the upper right exit button X, it does. Is there another command I need to use in addition to unload form to get the program to completely release the file?

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Closing form doesn't stop program

    How are you opening the file?
    If posting code please use code tags, see here.

  3. #3
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Closing form doesn't stop program

    Please Login or Register  to view this content.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  4. #4
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Closing form doesn't stop program

    Hi there,

    I suspect that the problem lies in the method which you are using for closing the UserForm.

    Insert the following code in a standard VBA CodeModule:

    Please Login or Register  to view this content.
    and use the following code in the CodeModule associated with the UserForm itself:

    Please Login or Register  to view this content.

    In general, UserForms should be instantiated, displayed (.Show) and unloaded from a calling routine located in a CodeModule which is separate from the CodeModule of the UserForm.

    The UserForm should be hidden (not unloaded) by one or more routines located in the CodeModule associated with the UserForm.


    Hope this helps - please let me know how you get on.

    Regards,

    Greg M
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    10-12-2018
    Location
    Leesburg, FL
    MS-Off Ver
    2013
    Posts
    113

    Re: Closing form doesn't stop program

    Quote Originally Posted by Greg M View Post
    Hi there,

    I suspect that the problem lies in the method which you are using for closing the UserForm.

    Insert the following code in a standard VBA CodeModule:

    Please Login or Register  to view this content.
    and use the following code in the CodeModule associated with the UserForm itself:

    Please Login or Register  to view this content.

    In general, UserForms should be instantiated, displayed (.Show) and unloaded from a calling routine located in a CodeModule which is separate from the CodeModule of the UserForm.

    The UserForm should be hidden (not unloaded) by one or more routines located in the CodeModule associated with the UserForm.


    Hope this helps - please let me know how you get on.

    Regards,

    Greg M
    Thanks Greg. This was helpful. One follow up question if you don't mind. I open a .csv file initially using the first segment of code to see what it contains so I know its dimensions and fields and populate a combobox and then close it. I then open it for editing using the second method and after the changes are made the file is saved, but I intentionally haven't exited the form yet at this point. However, the file that I edited and saved cannot be closed at this point while the form is still running. Why is that? I have included my entire program below for reference.


    Please Login or Register  to view this content.

  6. #6
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Closing form doesn't stop program

    Hi again,

    Many thanks for your feedback and also for the Reputation increase - much appreciated!

    Ah ok, if I had read your original post more closely I might have understood the problem better - sorry about that.

    By default, a UserForm is Modal, which means that cells, worksheets, workbooks etc. are "untouchable" for as long as that UserForm is displayed. If you want to be able to access other items (e.g. to close the edited workbook) while a UserForm remains displayed, you must open it as a Modeless UserForm, i.e. instead of "TracFone.Show" you should use "TracFone.Show vbModeless".


    Hope this helps - as before, please let me know how you get on.

    Best regards,

    Greg M

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Closing form doesn't stop program

    Where in the code are you trying to close the CSV file you've opened?

    You should be able to do that whether the userform is modal or modeless.

  8. #8
    Forum Contributor
    Join Date
    10-12-2018
    Location
    Leesburg, FL
    MS-Off Ver
    2013
    Posts
    113

    Re: Closing form doesn't stop program

    Quote Originally Posted by Greg M View Post
    Hi again,

    Many thanks for your feedback and also for the Reputation increase - much appreciated!

    Ah ok, if I had read your original post more closely I might have understood the problem better - sorry about that.

    By default, a UserForm is Modal, which means that cells, worksheets, workbooks etc. are "untouchable" for as long as that UserForm is displayed. If you want to be able to access other items (e.g. to close the edited workbook) while a UserForm remains displayed, you must open it as a Modeless UserForm, i.e. instead of "TracFone.Show" you should use "TracFone.Show vbModeless".


    Hope this helps - as before, please let me know how you get on.

    Best regards,

    Greg M
    Thanks Greg! Both of your posts were very informative and useful to me. I tried to give you more credit for the additional response, but the system wouldn't let me.

  9. #9
    Forum Contributor
    Join Date
    10-12-2018
    Location
    Leesburg, FL
    MS-Off Ver
    2013
    Posts
    113

    Re: Closing form doesn't stop program

    Quote Originally Posted by bvwalker1 View Post
    Thanks Greg! Both of your posts were very informative and useful to me. I tried to give you more credit for the additional response, but the system wouldn't let me.
    Where is TracFone.Show located? I do not call this explicitly anywhere so is it being called behind the scenes somewhere? It's my main form.
    Thanks, Greg!

  10. #10
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Closing form doesn't stop program

    Hi Brian,

    Many thanks for your PM - I hope my reply helps to keep you moving in the right direction.


    Hi Norie,

    The edited workbook is NOT being closed from the UserForm - my understanding is that the OP wants to keep the workbook open (and "accessible") while the UserForm remains displayed.


    Regards to you both,

    Greg M
    Last edited by Greg M; 01-09-2019 at 07:43 PM. Reason: Second addressee included

+ 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. UserForm Disappears After Saving and Closing Program
    By TedN in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-04-2012, 11:30 PM
  2. Replies: 5
    Last Post: 11-19-2012, 12:06 PM
  3. Userform - stop user saving or closing form is not complete
    By denise6372 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-18-2012, 12:24 AM
  4. Form closing Excel program?
    By jimbo_jones in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-02-2007, 03:34 PM
  5. Macro for Saving and Closing Program
    By dxer in forum Excel General
    Replies: 5
    Last Post: 11-09-2006, 09:49 AM
  6. Closing Excel Program correctly?
    By T.c.Goosen1977 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-07-2006, 11:04 AM
  7. Closing a external legacy program using VBA
    By Byron in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-09-2005, 12:05 AM
  8. Saving and Closing multiple files and Excel program
    By Roger in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-18-2005, 11:05 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