Userform Text Box Value Saving On Close!?

  • I'm new here & I've been doing VBA for about a year, but I can't figure this one out:
    I have a userform1 with 12 text boxes with values/text and on this userform there is a cmdbutton to bring up userform2 to change the values/text of the textboxes on the userform1, it changes all the values/text on all the textboxes on userform1, however I want it to save these changes when the 1st userform closes & then re-opens?? How do I do this??


    Thanks

  • Re: Userform Text Box Value Saving On Close!?


    Hi CMBENGR. Welcome to Ozgrid


    I can think of two ways.


    1. Instead of closing userform1, hide it. When you show it again the data will be there.


    2. Write the data to a hidden worksheet and close the userform1. When you open the userform1 again in the initialize code copy the data from the hidden worksheet to the textboxes.


    Hope this helps


    Bill

    [FONT="Arial Black"][COLOR="blue"][SIZE="4"]Bill[/SIZE][/COLOR][/FONT]
    Tip: To avoid chasing code always use Option Explicit.

  • Re: Userform Text Box Value Saving On Close!?



    Thanks Bill,
    However, that won't work! All my values from userform1 have values that have to go onto a worksheet! It just won't save the values on userform1 when it closes & re-opens!
    The only way it saves the values is if I go into VBA & set each value/text of each text box. I want to be able to change the values & SAVE them when the userform closes!


    Thanks,
    Harry

  • Re: Userform Text Box Value Saving On Close!?


    CMBENGR.


    Quote


    I want it to save these changes when the 1st userform closes & then re-opens?? How do I do this??


    Do you want to save the data so that when userform1 opens again the data is still there or do you want to save the data to a spread sheet when you close the userform1?


    Why are you opeing a second userform instead of changeing the texed boxes on userfomr1 directly?


    Bill

    [FONT="Arial Black"][COLOR="blue"][SIZE="4"]Bill[/SIZE][/COLOR][/FONT]
    Tip: To avoid chasing code always use Option Explicit.

  • Re: Userform Text Box Value Saving On Close!?



    I want to save the data when userform1 closes & then re-opens again!
    I could do away with userform2, however, it works! Userform2 is used to change the values/text of userform1's text boxes. Let me explain further: On userform1 there is textboxes over togglebuttons, when you select a certain togglebutton(enable), the combobox is enabled & you can select from the values on that combobox. I want to change the textbox text. When you select the togglebutton, the textbox that is over it enables & changes color. I don't want to change the togglebutton.caption because they have values for the worksheet. I hope I made this clear!
    Thankyou so much!

  • Re: Userform Text Box Value Saving On Close!?


    Here's my code:


    Please help, I know my code could probably use some shortcuts/neatening, but it works!
    I'm still new at VBA! Thanks!
    Harry

  • Re: Userform Text Box Value Saving On Close!?


    try something like this



    HTH

  • Re: Userform Text Box Value Saving On Close!?


    Quote from toecutter

    try something like this



    HTH


    Sorry, but no!
    All I really want, in a nutshell is when userform1 closes that it saves the new values/text in the text boxes, & when I re-open it the same values are still there!
    I have the transfrer of data from userform to usrefrom, no problem there, even transferring data from userform to userform to worksheet, that isn't the problem! It actually has nothing to do with the worksheets! I just want to (re-text) the text boxes, that's it! I can't do it!
    I tried everything. It must be something that when form1 unloads it saves the new text/value when it closes!
    Thank You!

  • Re: Userform Text Box Value Saving On Close!?


    When a userform closes, the values of the controls revert to the defaults set at design time.


    If you want the values of the textboxes to be in the userform when it is loaded again,


    1) Move the values off the userform to a data storage location. Static variables might be one choice, spreadsheet cells would probably be the easiest.
    2) Then unload the useform.
    3) Re-set the textbox values from data storage.
    4) Re-load the userform.


    If you hide the userform, rather than unloading it, the values will be preserved in the textboxes until the next time the userform is loaded and data storage is not needed.

  • Re: Userform Text Box Value Saving On Close!?


    ozgrid.com/forum/core/index.php?attachment/22808/


    That's a great idea! Thank You! Check my form out: Select "Set Default Values" and you'll see what I'm talking 'bout!


    I just thought about it, I need userform1, it sets all the values/formulas on my sheet!
    You mean to tell me that when a userform closes that it can't "SAVE" it's text/value in any of the "Text boxes" ?
    There has to be a way!
    Thanks,

  • Re: Userform Text Box Value Saving On Close!?


    Which idea are you liking, Bill Rockenbach's idea to hide the form or toecutter's plan to store the textboxes' values in the spreadsheet while the uf is unloaded.


    To impliment Bill's hiding, replace

    Code
    1. Unload Userform1

    with

    Code
    1. Userform1.Hide

    at the end of CommandButton1_Click.


    To impliment toecutter's range storage, how many textboxes do you have and where on the spreadsheet do you have a row of that many cells to dedicate to uf data storage?

  • Re: Userform Text Box Value Saving On Close!?




    I need the UNLOAD! Take a look, I have 12 TXTBOXES! The form rename does just that, it renames the text boxes in UF1, but it won't save them when the form unloads, that's the key: I need this form,(Form1 - Set Defaults values) it sets all the values/formulas on the worksheet!
    Thanks!

  • Re: Userform Text Box Value Saving On Close!?


    These two routines will do what you need.

  • Re: Userform Text Box Value Saving On Close!?


    Harry,


    I originally gave you two ideas (Hide the form or write the text values to a hidden sheet).


    Since you say you have to close the form here is the code to save the data on unloading the form and retriving the data when the form is re-loaded. Both procedures go in the userform code module. The code loops through all the controls on the userform and takes action only on the texboxes.



    May I suggest the next time you post a question be very clear on what you are asking. It will save us all a lot of time.
    Hope this works for you.


    Bill

    [FONT="Arial Black"][COLOR="blue"][SIZE="4"]Bill[/SIZE][/COLOR][/FONT]
    Tip: To avoid chasing code always use Option Explicit.

  • Re: Userform Text Box Value Saving On Close!?


    These two routines will do what you need.

    That's What was i looking a code. But I couldnt do edit it. I'm trying editing it for A to Z but When i change A1:L1 as A1:Z1 and For i 1 to 26 then then i got an error. Can Someone Help me please ?