Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Transfer name between forms

Status
Not open for further replies.

ckhunley

Technical User
Jul 26, 2004
33
0
0
US
I have a text box on a user form. I want another user form to be able to reference the value from this text box.

e.g. Activesheet.name = "Text " &textbox.value

I tried making the Sub public in that module, but it doesn't recognize it in the module for the other form.
Any ideas?
Thanks,
Chris
 
Just reference the Textbox along with the Form name.

For example:

Code:
Sub UserForm1_Activate()
    Msgbox UserForm2.Textbox1.Value
End Sub

*cLFlaVA
----------------------------
A polar bear walks into a bar and says, "Can I have a ... beer?"
The bartender asks, "What's with the big pause?
 
Ok, thanks for the tip. I plugged in the userform reference and it seems to recognize. I hit SHIFT +F2 and it went to the correct userform and found the value it was supposed to. But when I run it I get an error saying "Subscript out of range"

This is the code that it is having a problem with, I am not sure if there might be something else wrong with it.

Worksheets("Toggle " & Starthydraulics.toggle.Value).Activate

Starthydraulics is the name of the userform which I am referencing, and toggle is the name of the textbox.

Thanks,
Chris
 
Subscript out of range -

Most likely because it's trying to "Activate" a worksheet that doesn't exist.

Comment out that line, and replace it with

Msgbox "'Toggle " & Starthydraulics.toggle.Value) & "'"

And see if what the message box displays between the two ' marks is precisely the name of the Worksheet.

*cLFlaVA
----------------------------
A polar bear walks into a bar and says, "Can I have a ... beer?"
The bartender asks, "What's with the big pause?
 
Ok, so I have a default value for the text box. The user then enters whatever value they think is appropriate. When I ran that little test you suggested, it printed the default entry into the messagebox rather than what I had entered. I realized that was because I hadn't ran the other userform fist in order to set that value. It is working great now, as long as I run everything sequentailly. Thank you very much for your help.
Chris
 
Is there a way to keep the value of the textbox from the last entry by the user? I started running my forms, but something went wrong so I had to go in and correct the error. When I started it up again where I left off, it could not recognize the worksheet because the value of the textbox had diverted back to the default. Is there a way to keep the value on the last entry even if the file is closed or the code aborted?
Thanks,
Chris
 
Not directly. UserForms are fully created at run-time. They do not keep persistent data. Even the default text is created, by being a property, at run-time. You could however at run-time, take the value and put it somewhere in your file. It could then be retrieved.

Gerry
 
Take a look at the ControlSource property of the textbox.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top