Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Assigning the name of a userform/control to a changing string

I want to attach a name to a userform (i.e. userform1,2,3 etc) or a control
within a form (i.e. TextBox1,2,3 etc) by means of a loop. How do I name the
userform/control with a variable such as a string ...

Dim UF as UserForm
Dim str as string
Dim j as Integer

For j = 1 to 5
str = ³UserForm² & j
UF.Name = str
UF.Show
Next j

- It doesn¹t work, but is it close?

Thanks for any help.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default Assigning the name of a userform/control to a changing string

Hi Brad

What you want can only be accomplished, if the userform/control
is created at run time. It's not possible to alter a name given at design
time programmically.

This example shows the basics:

Private Sub UserForm_Initialize()
Dim Counter As Long

For Counter = 1 To 3
Me.Controls.Add "forms.checkbox.1", Name:="Burger" & Counter
Next Counter

Me.Controls("Burger2").Value = True ' or Me!burger2.Value = True

MsgBox Me!burger2.Value
End Sub



--
Best Regards
Leo Heuser
MVP Excel

Followup to newsgroup only, please.

"Brad Patterson" skrev i en meddelelse
...
I want to attach a name to a userform (i.e. userform1,2,3 etc) or a control
within a form (i.e. TextBox1,2,3 etc) by means of a loop. How do I name the
userform/control with a variable such as a string ...

Dim UF as UserForm
Dim str as string
Dim j as Integer

For j = 1 to 5
str = "UserForm" & j
UF.Name = str
UF.Show
Next j

- It doesn't work, but is it close?

Thanks for any help.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Assigning the name of a userform/control to a changing string

Thanks leo, but I wanted to name the item iteratively * when they already
exist.

It¹s just trying to refer to the textbox with a string that had me stumped,
but I know the answer thanks to your post and the Me.Control(²textbox
....²).value command.

Thanks!


in article , Leo Heuser at
wrote on 16/7/03 6:37 PM:

Private Sub UserForm_Initialize()
Dim Counter As Long

For Counter = 1 To 3
Me.Controls.Add "forms.checkbox.1", Name:="Burger" & Counter
Next Counter

Me.Controls("Burger2").Value = True ' or Me!burger2.Value = True

MsgBox Me!burger2.Value
End Sub




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
Finding a single word match in a text string and assigning a code Morton Detwyler[_2_] Excel Worksheet Functions 6 September 15th 09 09:18 PM
Enter date in userform using Calendar Control Scotty9349 Excel Discussion (Misc queries) 1 March 4th 09 07:02 PM
Passing variable values to userform control KJ-clueless Excel Discussion (Misc queries) 2 November 27th 07 10:51 PM
control toolbox and userform toolbars in XL 03 Dave F[_2_] Excel Discussion (Misc queries) 2 August 8th 07 08:04 AM
Combo Box Control keeps changing sizes Michael Excel Worksheet Functions 0 February 16th 05 01:25 AM


All times are GMT +1. The time now is 06:10 PM.

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"