Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 116
Default Easy One - Syntax for variables in TextBox & Label names

Hello:

What is the correct syntax for including a variable (in this case "i") in
the name of a TextBox and/or Label?

I have a list of TextBoxes and Labels on a userform and I want to program a
reset button to change what is displayed back to the defaults. I need
something like this:

Private Sub CommandButton8_Click()
For i = 1 To 13
TextBox(i).Text = "0"
Label(i).Caption = "N/A"
Next i
End Sub

I'm getting a Sub or Function not defined error, and I know it's because the
syntax is wrong. Help is appreciated.

Thanks,
MARTY

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Easy One - Syntax for variables in TextBox & Label names

Could be looking for the parent to the textbox and label. i.e.
UserForm1.TextBox(i) and UserForm1.Label(i), etc.

"Marty" wrote:

Hello:

What is the correct syntax for including a variable (in this case "i") in
the name of a TextBox and/or Label?

I have a list of TextBoxes and Labels on a userform and I want to program a
reset button to change what is displayed back to the defaults. I need
something like this:

Private Sub CommandButton8_Click()
For i = 1 To 13
TextBox(i).Text = "0"
Label(i).Caption = "N/A"
Next i
End Sub

I'm getting a Sub or Function not defined error, and I know it's because the
syntax is wrong. Help is appreciated.

Thanks,
MARTY

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default Easy One - Syntax for variables in TextBox & Label names

For i = 1 To 13
Controls("TextBox" & i).Value = "0"
Controls("Label" & i).Caption = "N/A"
Next i

Hth,
Merjet
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 116
Default Easy One - Syntax for variables in TextBox & Label names

Nope. I tried this as a test based on your respone:

Private Sub CommandButton8_Click()
For i = 9 To 13
DATAENTRY.TextBox(i).Text = "0"
Next i
End Sub

and now I get a "method or data member not found" error. The ".TextBox"
part is highlighted while the error message is up, so apparently it doesn't
like "TextBox" without an integer suffix. This is what I'm trying to do:
make a variable suffix.

Other ideas?

"JLGWhiz" wrote:

Could be looking for the parent to the textbox and label. i.e.
UserForm1.TextBox(i) and UserForm1.Label(i), etc.

"Marty" wrote:

Hello:

What is the correct syntax for including a variable (in this case "i") in
the name of a TextBox and/or Label?

I have a list of TextBoxes and Labels on a userform and I want to program a
reset button to change what is displayed back to the defaults. I need
something like this:

Private Sub CommandButton8_Click()
For i = 1 To 13
TextBox(i).Text = "0"
Label(i).Caption = "N/A"
Next i
End Sub

I'm getting a Sub or Function not defined error, and I know it's because the
syntax is wrong. Help is appreciated.

Thanks,
MARTY

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Easy One - Syntax for variables in TextBox & Label names

Hi

the code below is one way to do it

Option Explicit
Dim Ctrl As Control
Dim i As Integer
Private Sub CommandButton1_Click()

For i = 1 To 13

Set Ctrl = Me.Controls("TextBox" & i)

Ctrl.Value = ""

Set Ctrl = Me.Controls("Label" & i)

Ctrl.Caption = ""

Next

End Sub

Hope this helps

Steve



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 116
Default Easy One - Syntax for variables in TextBox & Label names

Perfect. Thanks.

"merjet" wrote:

For i = 1 To 13
Controls("TextBox" & i).Value = "0"
Controls("Label" & i).Caption = "N/A"
Next i

Hth,
Merjet

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
Easy Syntax question: referring to worksheet by VBA name KR Excel Programming 2 November 22nd 04 07:53 PM
Is there an easy way calculate 2 variables in conditional sum wiz. Liketoknow Excel Worksheet Functions 1 November 10th 04 09:34 AM
Easy VBA Syntax Question Hulk[_6_] Excel Programming 4 October 13th 04 07:23 PM
Easy VBA Syntax Question Hulk[_7_] Excel Programming 0 October 13th 04 06:41 PM
easy question : textbox Yan Robidoux Excel Programming 6 August 9th 04 01:05 PM


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