vba: how to save the textbox value on an userform?

h711

Board Regular
Joined
Jun 23, 2008
Messages
164
I have 2 userforms. On the main form, there is a button called "Setting". Click on it will bring up the second form. On the second form, there is a textbox1 which has it's value defaulted to "abc". There is another button called "SaveAndQuit". Click on it will close the form #2 and return to form #1.

If I don't change any thing, textbox1.value will always be "abc", but I want my program to remember the change I made to textbox1. That is, when an user typed "efg" to textbox1 and click "SaveAndQuit", textbox1.value should be changed to "efg". When that user click "Setting" again, he will see textbox1 is "efg" instead of "abc".

The textbox1.value will be set back to default "abc" after all operation finished. That means, the value change made to textbox1 is not permanent to the program.

Private sub userform_initialize()
textbox1.value="abc"
end sub

Private sub textbox1()
end sub

private sub SaveAndQuit()
unload form2
end sub


Thanks!
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
In the SaveAndQuit thing, hide the form instead of unloading it. Then, you can still refer to its members from the other form.

For example, you could create a public variable (or better yet, private variable + public property) to store the value, then Form 1 will fetch that value and unload Form 2.
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,236
Members
448,555
Latest member
RobertJones1986

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