Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 113
Default Variable Control name

Hi there, I have a sub which gets the value of a Userform (name UF0_QCP)
control name passed into it (tb) but I'm having a little difficulty with the
syntax:

Dim TBC As control
Set TBC = Controls("UF0_QCP." & tb)

What is the missing link please? Regards, Brett
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Variable Control name

I am not sure I understood your question...Are you trying to pass the control
name as a variable ....as below

Private Sub CommandButton1_Click()
Dim TBC As Control
Dim strControl As String
strControl = "TextBox1"
Set TBC = UserForm1.Controls(strControl)
MsgBox TBC.Text
End Sub

--
If this post helps click Yes
---------------
Jacob Skaria


"Brett" wrote:

Hi there, I have a sub which gets the value of a Userform (name UF0_QCP)
control name passed into it (tb) but I'm having a little difficulty with the
syntax:

Dim TBC As control
Set TBC = Controls("UF0_QCP." & tb)

What is the missing link please? Regards, Brett

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Variable Control name

While the UserForm is the default object for all controls on it (meaning you
don't have to qualify the control), you can do it (if you want) this way...

Set TBC = UF0_QCP.Controls(tb)

Note: Controls is a property of the UserForm

--
Rick (MVP - Excel)


"Brett" wrote in message
...
Hi there, I have a sub which gets the value of a Userform (name UF0_QCP)
control name passed into it (tb) but I'm having a little difficulty with
the
syntax:

Dim TBC As control
Set TBC = Controls("UF0_QCP." & tb)

What is the missing link please? Regards, Brett


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 113
Default Variable Control name

Hi Rick, thanks for that, works like a charm. Are you suggesting that the
code could be simpler "(if you want)"? Regards, Brett

"Rick Rothstein" wrote:

While the UserForm is the default object for all controls on it (meaning you
don't have to qualify the control), you can do it (if you want) this way...

Set TBC = UF0_QCP.Controls(tb)

Note: Controls is a property of the UserForm

--
Rick (MVP - Excel)


"Brett" wrote in message
...
Hi there, I have a sub which gets the value of a Userform (name UF0_QCP)
control name passed into it (tb) but I'm having a little difficulty with
the
syntax:

Dim TBC As control
Set TBC = Controls("UF0_QCP." & tb)

What is the missing link please? Regards, Brett



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 113
Default Variable Control name

Hi Jacob, thanks for your response (apologies for delay in returning - had to
sleep!).
I tried Rick's suggestion first and it did the job. Regards, Brett

"Jacob Skaria" wrote:

I am not sure I understood your question...Are you trying to pass the control
name as a variable ....as below

Private Sub CommandButton1_Click()
Dim TBC As Control
Dim strControl As String
strControl = "TextBox1"
Set TBC = UserForm1.Controls(strControl)
MsgBox TBC.Text
End Sub

--
If this post helps click Yes
---------------
Jacob Skaria


"Brett" wrote:

Hi there, I have a sub which gets the value of a Userform (name UF0_QCP)
control name passed into it (tb) but I'm having a little difficulty with the
syntax:

Dim TBC As control
Set TBC = Controls("UF0_QCP." & tb)

What is the missing link please? Regards, Brett



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Variable Control name

If the code is in the UserForm's module, then you can refer to the UserForm
using the Me object...

Set TBC = Me.Controls(tb)

or, since the Controls parent is always the UserForm (when the code is
within the UserForm's module), you can leave it out altogether...

Set TBC = Controls(tb)

--
Rick (MVP - Excel)


"Brett" wrote in message
...
Hi Rick, thanks for that, works like a charm. Are you suggesting that the
code could be simpler "(if you want)"? Regards, Brett

"Rick Rothstein" wrote:

While the UserForm is the default object for all controls on it (meaning
you
don't have to qualify the control), you can do it (if you want) this
way...

Set TBC = UF0_QCP.Controls(tb)

Note: Controls is a property of the UserForm

--
Rick (MVP - Excel)


"Brett" wrote in message
...
Hi there, I have a sub which gets the value of a Userform (name
UF0_QCP)
control name passed into it (tb) but I'm having a little difficulty
with
the
syntax:

Dim TBC As control
Set TBC = Controls("UF0_QCP." & tb)

What is the missing link please? Regards, Brett




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 113
Default Variable Control name

OK, well the shorter the better as far as Me.Is.Concerned. Thanks Rick, Brett

"Rick Rothstein" wrote:

If the code is in the UserForm's module, then you can refer to the UserForm
using the Me object...

Set TBC = Me.Controls(tb)

or, since the Controls parent is always the UserForm (when the code is
within the UserForm's module), you can leave it out altogether...

Set TBC = Controls(tb)

--
Rick (MVP - Excel)


"Brett" wrote in message
...
Hi Rick, thanks for that, works like a charm. Are you suggesting that the
code could be simpler "(if you want)"? Regards, Brett

"Rick Rothstein" wrote:

While the UserForm is the default object for all controls on it (meaning
you
don't have to qualify the control), you can do it (if you want) this
way...

Set TBC = UF0_QCP.Controls(tb)

Note: Controls is a property of the UserForm

--
Rick (MVP - Excel)


"Brett" wrote in message
...
Hi there, I have a sub which gets the value of a Userform (name
UF0_QCP)
control name passed into it (tb) but I'm having a little difficulty
with
the
syntax:

Dim TBC As control
Set TBC = Controls("UF0_QCP." & tb)

What is the missing link please? Regards, Brett




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting a VBA Control as a variable J Streger Excel Programming 2 November 21st 06 04:58 PM
Variable control tip text Steve Excel Discussion (Misc queries) 3 June 30th 05 03:48 PM
variable form control Roman[_4_] Excel Programming 2 June 15th 05 08:20 AM
using variable for a control name mark kubicki Excel Programming 1 April 3rd 04 12:31 AM
Variable Control Names Garry Jones Excel Programming 4 October 3rd 03 10:45 PM


All times are GMT +1. The time now is 10:19 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"