passing userform values

rickblunt

Well-known Member
Joined
Feb 18, 2008
Messages
609
Office Version
  1. 2019
Platform
  1. Windows
Hello, I have two userforms and I have a commandbutton on useform1 that calls for userform2. On userform1 I have a text value in textbox1 that I want to pass on to textbox1 on userform2 when it launches. I thought the code below should be all I need, but when I launch userform 2 the textbox remains blank. Did a couple of quick searches through the forum and this does seem to be the correct code. But I cant figure out what I am missing. Userform1 stays open while I have userform2 open, so it should still see the value in the textbox.... Should I not use the initialize event? I appreciate any input - Rick


Code:
Private Sub UserForm_Initialize()


Userform2.textbox1.Text = Userform1.TextBox1.Text




End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hello, I have two userforms and I have a commandbutton on useform1 that calls for userform2. On userform1 I have a text value in textbox1 that I want to pass on to textbox1 on userform2 when it launches. I thought the code below should be all I need, but when I launch userform 2 the textbox remains blank. Did a couple of quick searches through the forum and this does seem to be the correct code. But I cant figure out what I am missing. Userform1 stays open while I have userform2 open, so it should still see the value in the textbox.... Should I not use the initialize event? I appreciate any input - Rick


Code:
Private Sub UserForm_Initialize()


Userform2.textbox1.Text = Userform1.TextBox1.Text






End Sub

That code works just fine for me.

Edit: Maybe post your whole code, and we can help you spot something that might be causing it.
 
Last edited:
Upvote 0
Thanks for replying Peter H, and thank you for confirming this for me. I was pulling one of those "all nighters" and when I thought I was done with the project my boss, threw in one of those, "before you leave could you add in this?" kinds of things. When I got back in this morning I realized that buried in the code the button that I was using to call that second userform was emptying out the contents of the textbox as it passed it onto the second textbox.
I appreciate your input on this - thanks again.
 
Upvote 0
Thanks for replying Peter H, and thank you for confirming this for me. I was pulling one of those "all nighters" and when I thought I was done with the project my boss, threw in one of those, "before you leave could you add in this?" kinds of things. When I got back in this morning I realized that buried in the code the button that I was using to call that second userform was emptying out the contents of the textbox as it passed it onto the second textbox.
I appreciate your input on this - thanks again.
I know how that goes. Lol. Glad to hear you got it all worked out.
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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