+ Reply to Thread
Results 1 to 17 of 17

Userform keeps/retains data previously entered when closed and then reopened.

  1. #1
    Forum Contributor
    Join Date
    02-13-2018
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    211

    Userform keeps/retains data previously entered when closed and then reopened.

    Hello,

    I have a small userform with textboxes and combo boxes. I want the user to be able to enter that data via userform to Sheet1 and then close the form. But, I want the userform to retain all the data that was previously entered. So when the userform opens back up it has all the previous data in it that was entered.

    I have looked at a few ways, but need some help.

    1 way was adding a blank hidden sheet in the file and doing a call method to it.

    Is there code I can write to make sure the userform keeps the data in it even after the form is closed and then reopened?

    thanks - workbook with the userform and code is attached.
    Attached Files Attached Files

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,120

    Re: Userform keeps/retains data previously entered when closed and then reopened.

    Change this

    Please Login or Register  to view this content.
    To this:
    Please Login or Register  to view this content.
    And comment this out:
    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    02-13-2018
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    211

    Re: Userform keeps/retains data previously entered when closed and then reopened.

    that worked, thanks!

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,120

    Re: Userform keeps/retains data previously entered when closed and then reopened.

    You're welcome.




    You may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  5. #5
    Forum Contributor
    Join Date
    02-13-2018
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    211

    Re: Userform keeps/retains data previously entered when closed and then reopened.

    @TMS,

    I reopened this thread. I noticed when I close the workbook and then reopen the workbook, the form clears again. So the keeping the data in the form works per above fixes, however when I close and reopen the workbook, the form opens up and has cleared all the previous data entered unfortunately. Is there a way I can write code to make sure that the data stays in the form even when workbook is closed and then reopened? Thanks

  6. #6
    Valued Forum Contributor
    Join Date
    11-29-2022
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    435

    Re: Userform keeps/retains data previously entered when closed and then reopened.

    You can use a sheet in the book to update with the results from the userform. Then use the UserForm_Initalize event to pull that data in from the sheet.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,120

    Re: Userform keeps/retains data previously entered when closed and then reopened.

    The form does not have anything in the fields. Therefore, when you close and re-open the workbook, and reload the form it will be clear.

    As has been suggested, you can save and load the field content to/from a worksheet. That would need a different approach to the solution offered.

    When you initialise the form, you need to read the value from the sheet. When you close or hide the form, you need to save the current contents of the fields to the sheet.

  8. #8
    Forum Contributor
    Join Date
    02-13-2018
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    211

    Re: Userform keeps/retains data previously entered when closed and then reopened.

    Ok, I am trying to figure out how I can do this, wondering if code like this will work, but it is not working. Any thoughts?

    Please Login or Register  to view this content.
    Last edited by Shruder; 04-01-2024 at 05:47 PM.

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,120

    Re: Userform keeps/retains data previously entered when closed and then reopened.

    That's not what your form is called. It's UserForm2a

    Working code plus some minor tweaks (mostly to tidy up the code)

    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    02-13-2018
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    211

    Re: Userform keeps/retains data previously entered when closed and then reopened.

    That worked TMS.

    Now, is there a way that I can get the VBA code in the userform to automatically update once Sheet1 is copied within the workbook? I put a sheet in here "Test". So ideally once the end user uses the userform on Sheet1, they will copy Sheet1 to a new sheet (in this case it is 'Test'). I then want them to be able to use that userform on both the 'Test' sheet and the 'Sheet1'.

    So essentially, I am looking for a way to get the existing VBA code updated when the user copies 'Test' to a new sheet. Is that possible? I have been researching and I have not seen anything that addresses this - workbook is attached!
    Attached Files Attached Files
    Last edited by Shruder; 04-15-2024 at 11:54 AM.

  11. #11
    Forum Contributor
    Join Date
    02-13-2018
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    211

    Re: Userform keeps/retains data previously entered when closed and then reopened.

    !!!!!!!!!!!!!! UPDATE TO MY POST FROM 04-15-2024, 07:18AM !!!!!!!!!!!!!!!!!

    I was able to add some code that will transfer userfrom data entered from any sheet so long as there is a sheetname in cell (B2) on Sheet1. This is good and what I wanted, however the issue still remains of the userfrom retaining data.

    Here is an example below -

    Enter sheetname in B2 of Sheet1

    Attachment 867080

    go to "Test" sheet and enter userform data. Everything works as pictured below with one exception.
    Attachment 867081


    If you got back into sheet1 userform it retains the same data that was entered in on the "Test" sheet.

    What I want is anytime sheet1 is copied to a new sheet, renamed and then the userform is used on that sheet it will retain that info. This way I can just copy the userform each time I need to add a new sheet and use that same userform for the initial data entry, and then also use it for when I need to update the data.

    any ideas?

    the workbook with code is attached.
    Attached Files Attached Files

  12. #12
    Forum Contributor
    Join Date
    02-13-2018
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    211

    Re: Userform keeps/retains data previously entered when closed and then reopened.

    I use Sheet2 as the dump for the UF data that was entered. However that does not help with the problem. I want to be able to just make a copy of a sheet that has the UF, and have it retain the old data that was entered.

  13. #13
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,120

    Re: Userform keeps/retains data previously entered when closed and then reopened.

    On your "dump" sheet, you need to create a row for each worksheet, with the sheet name in column A. This can be done pre-emptively or on the fly. If the number and name of the sheets is fairly static, you could do it as a one-off and that would make the coding simpler.

    Then, when you load a form on a specific sheet, you can look for the data in the row with that sheet's name. Similarly, when you close the form, you need to write the data to the row with that sheet's name.

    I'm guessing you have most of the code for loading and saving the data to/from the form. You just need to tweak it to choose a specific row.

  14. #14
    Forum Contributor
    Join Date
    02-13-2018
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    211

    Re: Userform keeps/retains data previously entered when closed and then reopened.

    Hi TMS, thank you for the response. I am attempting to do what you said above but am coming across roadblocks.

    I added the sheet names on the dumps sheet aka 'Sheet2" like you said above. However my issue is tweaking the code.

    Under the Private Sub cmdSubmit_Click() I am calling out PCnumber and then saying with PCnumber execute all the function from the code.


    Please Login or Register  to view this content.
    The problem is (I think) I am using the sheet name for the set method to rsh.

    I want the user form to retain the previously entered data per sheet. So if I pull up the UF in sheet A5669, it should not have the same UF data that was entered on Sheet1.

    workbook attached.
    Attached Files Attached Files

  15. #15
    Valued Forum Contributor MikeVol's Avatar
    Join Date
    12-30-2020
    Location
    Odessa / Ukraine
    MS-Off Ver
    MSO Prof Plus 2021 x64 (En)
    Posts
    578

    Re: Userform keeps/retains data previously entered when closed and then reopened.

    Hello. I don’t quite understand what you want to get as the final result from the form. But suddenly I guessed right, insert the following code into your form:
    Please Login or Register  to view this content.
    You launch the userform, in the drop-down list "ComboBox16" select the worksheet name in it and the selected worksheet is activated and the controls on the form from the active worksheet are filled in. But then I didn’t understand anything at all, then adjust the code yourself to suit your wishes. Good luck.
    NOTE: As the original poster/owner, only you can mark your thread as SOLVED (Thread Tools above Post #1).
    You can say "Thanks" in your thread to everyone who offered to help you.
    You can also reward them by clicking * "Add Reputation" under their username on the left.
    With Regards, MikeVol.

  16. #16
    Forum Contributor
    Join Date
    02-13-2018
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    211

    Re: Userform keeps/retains data previously entered when closed and then reopened.

    @ MikeVol,

    that code worked, thank you!

  17. #17
    Valued Forum Contributor MikeVol's Avatar
    Join Date
    12-30-2020
    Location
    Odessa / Ukraine
    MS-Off Ver
    MSO Prof Plus 2021 x64 (En)
    Posts
    578

    Re: Userform keeps/retains data previously entered when closed and then reopened.

    ...A few moment later...
    @Shruder, Thanks for the feedback and added rep point. Good luck.

+ 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] Retrieval of data entered in Userform after Userform is closed
    By rpcoates1956 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-05-2017, 04:10 PM
  2. [SOLVED] Edit Data Previously Entered Through Userform
    By cmoore24 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-21-2015, 10:45 AM
  3. [SOLVED] Information from userform overwriting data previously entered by same userform
    By ciresuark in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-20-2015, 02:10 PM
  4. How to have checkbox stay True when userform is closed and reopened
    By Gal403 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-02-2014, 12:57 PM
  5. Populating VBA userform and Fetch previously entered data edit and make new entry
    By vijaynadiad in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-07-2013, 11:59 AM
  6. Open a excel userform with values previously entered by user using VBA
    By anuraag1 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-17-2013, 07:02 AM
  7. [SOLVED] Data previously entered on UserForm dissappears, but still stored on worksheet - Excel VBA
    By eemiller1997 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-19-2012, 12:24 PM

Tags for this Thread

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