PDA

View Full Version : [SOLVED] Excel 2013>VBA>UserForm>TextBox>Name as variable



aworthey
07-29-2016, 07:31 AM
Hello,

I'm trying to call the name of a textbox on my userform from a variable. Is that possible?

I know that my variable is working correctly. And I know that the value I want to place in the textbox is working correctly. I just can't get the textbox name from the variable.

Here's the code:


Private Sub CommandButton5_Click()

Dim boxSMARTdest As String
Dim dest As MSForms.TextBox

boxSMARTdest = frmSMARTNumberPicker.bxSMRTvalue.Caption
dest = Forms("frmFinishTA").Controls(boxSMARTdest)

With dest
.Text = frmSMARTNumberPicker.Label1.Caption
End With

Unload Me

End Sub

mikerickson
07-29-2016, 07:48 AM
I'm pretty sure that the Forms("frmFinishTA") is a syntax error.
I'm very sure that you need to use the keyword Set when assigning the Textbox variable, dest.

aworthey
07-29-2016, 07:59 AM
mikerickson,

Thanks for responding.

How would I use the keyword Set when assigning the Textbox variable, dest? I'm not familiar with that.

aworthey
07-29-2016, 09:59 AM
I reread your post after I had more time...I understand what you're saying now! Ha.

aworthey
07-29-2016, 11:09 AM
Here's what I got to work:


Private Sub CommandButton5_Click()

Dim boxSMARTdest As String
Dim dest As MSForms.TextBox

boxSMARTdest = frmSMARTNumberPicker.bxSMRTvalue.Caption
Set dest = frmFinishTA.Controls(boxSMARTdest)

With dest
.Text = frmSMARTNumberPicker.Label1.Caption
End With

Unload Me

End Sub

p45cal
07-29-2016, 02:47 PM
Now you've developed it, shorten it (untested):
Private Sub CommandButton5_Click()
frmFinishTA.Controls(frmSMARTNumberPicker.bxSMRTvalue.Caption).Text = frmSMARTNumberPicker.Label1.Caption
Unload Me
End Sub