Supposing that you need the form opening next time displaying the last text used in TextBox1
, please use the next approach:
- Copy the next declarations on top of the form code (in the declarations area):
Option Explicit
'It is good to use relevant constants, able to better reflect their meaning:
Private Const MyApp As String = "MyApplication"
Private Const Sett As String = "Settings"
Private Const Txt1 As String = "Txt1Val"
- Put this code in the TextBox1
Change
event:
Private Sub TextBox1_Change()
SaveSetting MyApp, Sett, Txt1, TextBox1.Text
End Sub
- Copy the next code in the
Userform_Initialize
event:
Dim Txt1Val As String
Txt1Val = GetSetting(MyApp, Sett, Txt1, "No value")
If Not Txt1Val = "No value" Then Me.TextBox2.Text = Txt1Val
Now, when the user change the TextBox1
text, the new string is memorized in Registry and used to to be load during the next UserForm initialization...
If something unclear, do not hesitate to ask, please.