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

Within a user form I am trying to reduce the amount of code needed to
enter text into text box

I have two text boxes. TextBox1 and TextBox2

When Command Button 1 is clicked I want the result
TextBox1.Text = "This is my test text"

When Command Button 2 is clicked I want the result
TextBox2.Text = "This is my test text"

But I wish to use the same piece of code for both examples.

I am missing something here. This is my test example.

__________________________________________________ ___________

Private Sub CommandButton1_Click()
setar (1)
'when Command Button 1 is clicked it sends the number 1 as a variable to
the code
End Sub
__________________________________________________ ___________

Private Sub CommandButton2_Click()
setar (2)
'when Command Button 2 is clicked it sends the number 2 as a variable to
the code
End Sub
__________________________________________________ ___________

Private Sub setar(ArgValue As Integer)
TextBoxArgValue.Text = "This is my test text"
'Missing something here
End Sub

Bottom Line
-----------

How do I get Argvalue to place itself between the x of TextBoxand the .

?

On a similar note, how do I add this number mid text?

When Command Button 1 is clicked I want the result
TextBox1.Text = "This is my test 1 text"

When Command Button 2 is clicked I want the result
TextBox2.Text = "This is my test 2 text"



Garry Jones
Sweden

PS, Yes I know I can get the same effect by using unique code in each
command button control. But I have 198 command buttons so I want to use
the same code 198 times.
  #2   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel
external usenet poster
 
Posts: 35
Default Variable Control Names

Garry,

Try this for a start:

'--------
Private Sub setar(ArgValue As Integer)
Dim boxName As String
boxName = "Textbox" & ArgValue
Me.Controls(boxName).Value = boxName
End Sub
'--------

HTH
Anders Silvén

"Garry Jones" skrev i meddelandet
...
Within a user form I am trying to reduce the amount of code needed to
enter text into text box

I have two text boxes. TextBox1 and TextBox2

When Command Button 1 is clicked I want the result
TextBox1.Text = "This is my test text"

When Command Button 2 is clicked I want the result
TextBox2.Text = "This is my test text"

But I wish to use the same piece of code for both examples.

I am missing something here. This is my test example.

__________________________________________________ ___________

Private Sub CommandButton1_Click()
setar (1)
'when Command Button 1 is clicked it sends the number 1 as a variable to
the code
End Sub
__________________________________________________ ___________

Private Sub CommandButton2_Click()
setar (2)
'when Command Button 2 is clicked it sends the number 2 as a variable to
the code
End Sub
__________________________________________________ ___________

Private Sub setar(ArgValue As Integer)
TextBoxArgValue.Text = "This is my test text"
'Missing something here
End Sub

Bottom Line
-----------

How do I get Argvalue to place itself between the x of TextBoxand the .

?

On a similar note, how do I add this number mid text?

When Command Button 1 is clicked I want the result
TextBox1.Text = "This is my test 1 text"

When Command Button 2 is clicked I want the result
TextBox2.Text = "This is my test 2 text"



Garry Jones
Sweden

PS, Yes I know I can get the same effect by using unique code in each
command button control. But I have 198 command buttons so I want to use
the same code 198 times.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Variable Control Names

Try this:

Private Sub CommandButton1_Click()
setar (1)
'when Command Button 1 is clicked it sends the number 1 as a variable to
the code
End Sub
__________________________________________________ ___________

Private Sub CommandButton2_Click()
setar (2)
'when Command Button 2 is clicked it sends the number 2 as a variable to
the code
End Sub
__________________________________________________ ___________

Private Sub setar(ArgValue as Integer)
UserForm1.Controls("TextBox" & ArgValue).Text = "This is my test text"
'Missing something here
End Sub

Let me know if that doesn't work.

Mark

---
Mark Bigelow
mjbigelow at hotmail dot com
http://hm.imperialoiltx.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Variable Control Names

Mark Bigelow wrote:

Let me know if that doesn't work.


It worked, thanks. (Thanks to Anders as well).

Okay, next problem, similar.

I want to decide which worksheet to name with a variable

What am I missing here?

____________________________________________

Private Sub CommandButton1_Click()
setar (1)
'when Command Button 1 is clicked it sends the number 1 as a variable to
the code
End Sub
____________________________________________

Private Sub setar(ArgValue as Integer)
("Sheet" & ArgValue).Name = "NewName"
'Missing something here
End Sub
____________________________________________

What I want from the code is is

Sheet1.Name = "NewName"

Garry Jones
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Variable Control Names

Here's one way:

'-------
Sub setar(ArgValue As Integer)
Worksheets("Sheet" & ArgValue).Name = "NewName"
End Sub
'-------

HTH
Anders Silvén

"Garry Jones" skrev i meddelandet
...
Mark Bigelow wrote:

Let me know if that doesn't work.


It worked, thanks. (Thanks to Anders as well).

Okay, next problem, similar.

I want to decide which worksheet to name with a variable

What am I missing here?

____________________________________________

Private Sub CommandButton1_Click()
setar (1)
'when Command Button 1 is clicked it sends the number 1 as a variable to
the code
End Sub
____________________________________________

Private Sub setar(ArgValue as Integer)
("Sheet" & ArgValue).Name = "NewName"
'Missing something here
End Sub
____________________________________________

What I want from the code is is

Sheet1.Name = "NewName"

Garry Jones




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
Passing variable values to userform control KJ-clueless Excel Discussion (Misc queries) 2 November 27th 07 10:51 PM
Using form control names in SQL AaronC Excel Discussion (Misc queries) 0 July 14th 05 05:13 PM
Variable control tip text Steve Excel Discussion (Misc queries) 3 June 30th 05 03:48 PM
Today variable to calender control anonymous Excel Discussion (Misc queries) 2 March 10th 05 03:22 PM
Form control names Howard Kaikow Excel Programming 6 July 26th 03 08:24 PM


All times are GMT +1. The time now is 03:57 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"