referencing userform name

rickblunt

Well-known Member
Joined
Feb 18, 2008
Messages
609
Office Version
  1. 2019
Platform
  1. Windows
Greetings, I have 10 userforms - lets call them userforms1 and userform2 and userform3 and so on. And I would like in certain circumstances for these forms to be able to call a second userform that we will call userformA. However, I need to pass information from at least 1 textbox into a textbox on userformA, I would rather not build 10 userforms for each one of them, but just use userformA for all of them. So I am thinking that I could use a variable and just construct the code to be something like "i & userform name". I need to be able to reference the name of the userform that calls for it. Is this possible to do?

Thanks for any input - it is appreciated.


Code:
Private Sub UserFormA_Initialize()


            UserFormA.TextBox1.Text = UserForm1.TextBox1.Text        




End Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Maybe you would like to tell us what your ultimate goal is.
And why you think you need 10 UserForms

I have been using Excel for years and have never found a situation where I need 10 different UserForms in one Workbook.

There must be a easier way.
 
Upvote 0
Greetings, I have 10 userforms - lets call them userforms1 and userform2 and userform3 and so on. And I would like in certain circumstances for these forms to be able to call a second userform that we will call userformA. However, I need to pass information from at least 1 textbox into a textbox on userformA, I would rather not build 10 userforms for each one of them, but just use userformA for all of them. So I am thinking that I could use a variable and just construct the code to be something like "i & userform name". I need to be able to reference the name of the userform that calls for it. Is this possible to do?

Thanks for any input - it is appreciated.


Code:
Private Sub UserFormA_Initialize()


            UserFormA.TextBox1.Text = UserForm1.TextBox1.Text        




End Sub

Id say your on the right track. I did a two form test and passed textbox info (value) just as you have set up. I just use a command button to call form a and your code to pass value to form a from form one. I didn't use the .txt part FYI
 
Upvote 0
Yes, that part is easy, the trick is getting UserformA to know which userform called it into existence as it were.

Userforms are such a neat thing to use, they can do so many things so quickly. I use them for data entry, calculators, floating toolbars, sending emails - jeez the list goes on and on. I used to put buttons on worksheets, I still do a little but I often find it is much better to put them on userforms because you can dynamically change the buttons depending on what happens on the worksheet.

In this case I have many userforms and I want to generate an email and create a new data entry on a single worksheet to capture a failure event. While each userforms data does have its own sheet, I do not need to have a separate WS for each userform failure event, I can just put these all on the same sheet and generate a report off of that single WS. While every userform is different, this new userform is going to be gathering the exact same data from each userform; so I only need one. I just need to be able to tell this new userform who created it so that it knows what userform textbox1 to get its text from. Not sure how to make "UserForm1.Name" dynamic....
 
Upvote 0
Right before calling UserFormA from the other userforms, you can store the value of the textbox of the calling userform somewhere accessible by UserFormA like inside a Cell or in a Defined name .

For example in the calling userform(s) you will have :

Code:
Private Sub CommandButton1_Click()
    Names.Add "SourceTextBox", Me.TextBox1.Text
    UserFormA.Show
End Sub

And then in UserformA you will have :

Code:
Private Sub UserForm_Initialize()
    UserFormA.TextBox1.Text = [SourceTextBox]
    Names("SourceTextBox").Delete
End Sub
 
Upvote 0
Yes! That's a great idea, pass it to the WS and then call it from there. I think that should work perfectly, I will try that out and reply back. Now all I have to do to all of my current forms is add a single button (Or a few lines of code) to each of them instead of starting over ? Thanks to all for the help.
 
Upvote 0
Was not bothered just making a comment. I have a Workbook with many sheets. You can do the same thing with UserForms. One UserForm can have many pages. It called Multipages. Each Multipage can be set up to look like a seperate UserForm just like each sheet in a workbook can be setup differently. No need to have 1 sheet in 10 different Workbooks. Mutipages have tabs just like workbooks have tabs click on a tab an you have a whole new Userform. But if your happy with your setup that's great.
ouch....

sorry to have bothered you.
 
Upvote 0

Forum statistics

Threads
1,215,758
Messages
6,126,696
Members
449,331
Latest member
smckenzie2016

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