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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get value from TextBox created at design time

Status
Not open for further replies.

JRDumont

Programmer
Apr 4, 2004
7
US
I am trying to get values from Textboxes that I create at runtime. The number of textboxes needed can vary from user to user. I am able to create the TextBoxes and supply default values to them, however, I am having trouble getting their values later.
Any help would be gratly appreciated.
 
Hi,

Why don't you give each TextBox a name when they are created?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Hi Skip,
Thanks for the reply.

Here is the code I am using to create the textbox. The code create a textbox with a name of "ABC." I can pass a value upon creation but I can't capture the code later.
------------------------------------------------
Public Sub CreateTextBoxes()
Dim Test As String
Dim myText As TextBox
Dim NewTextBox As MSForms.TextBox
Dim T As String
T = "ABC"

Test = PropertyList(1)

'MsgBox test
Set NewTextBox = Me.Controls.Add("Forms.textbox.1", T)
With NewTextBox
'.name = T
.Top = 20
.Left = 150
.Width = 150
'.height = 12
'.Font.Size = 7
'.Font.name = "Tahoma"
'.BorderStyle = fmBorderStyleSingle
'.SpecialEffect = fmSpecialEffectFlat
End With
NewTextBox.Value = "123"

End Sub
---------------------------------------------

I have been testing which is why I have several lines commneted out.

Thanks.
 
You have that assignment COMMENTED OUT!!!


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
'.name = T"
The above line is commented out because I could not get it to work.

I then read I can include the name as shown below in the "Set" statement which should make the ".name" not necessary.

Set NewTextBox = Me.Controls.Add("Forms.textbox.1", T)

Thoughts?
 
This worked for me...
Code:
Dim T As String
Private Sub UserForm_Activate()
    Dim NewTextBox As MSForms.TextBox
    T = "ABC"
    
    'MsgBox test
    Set NewTextBox = Me.Controls.Add("Forms.textbox.1", T)
        With NewTextBox
            .Top = 20
            .Left = 150
            .Width = 150
        End With
    NewTextBox.Value = "123"
    Set NewTextBox = Nothing
End Sub

Private Sub UserForm_Click()
   MsgBox Me.Controls(T).Text
End Sub

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
That is awesome!!
Works Great.
Thanks very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top