Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default UserForm Controls References

I have a userform with several controls labelled tx1, tx2, tx3 ......txn

What I wish to do is write a procedure to process these within a loop.
eg
Dim x As Integer
Dim xfield As Variant
For x = 1 to n
xfield = "tx" & Cstr(x)
....
....code to act on each instance of the filed name
Next

The above does not work, can anyone provide a working solution that in
general allows me to build a string that holds the name of a userform
control, that can then be used in procedures ?

Thanks




----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! 100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default UserForm Controls References

Nigel,

Try something like the following:

Dim Ctrl As MSForms.TextBox
Dim Ndx As Integer
For Ndx = 1 To 3
Set Ctrl = UserForm1.Controls("tx" & Ndx)
Ctrl.Text = "Test Text " & Ndx
Next Ndx


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com


"Nigel" wrote in message
...
I have a userform with several controls labelled tx1, tx2, tx3 ......txn

What I wish to do is write a procedure to process these within a loop.
eg
Dim x As Integer
Dim xfield As Variant
For x = 1 to n
xfield = "tx" & Cstr(x)
....
....code to act on each instance of the filed name
Next

The above does not work, can anyone provide a working solution that in
general allows me to build a string that holds the name of a userform
control, that can then be used in procedures ?

Thanks




----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet

News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! 100,000
Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption

=---


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default UserForm Controls References

Chip,
Thanks so much, as ever the solution is simple but unless you know how.....!
I have tried your code and it works great
Cheers
Nigel

"Chip Pearson" wrote in message
...
Nigel,

Try something like the following:

Dim Ctrl As MSForms.TextBox
Dim Ndx As Integer
For Ndx = 1 To 3
Set Ctrl = UserForm1.Controls("tx" & Ndx)
Ctrl.Text = "Test Text " & Ndx
Next Ndx


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com


"Nigel" wrote in message
...
I have a userform with several controls labelled tx1, tx2, tx3 ......txn

What I wish to do is write a procedure to process these within a loop.
eg
Dim x As Integer
Dim xfield As Variant
For x = 1 to n
xfield = "tx" & Cstr(x)
....
....code to act on each instance of the filed name
Next

The above does not work, can anyone provide a working solution that in
general allows me to build a string that holds the name of a userform
control, that can then be used in procedures ?

Thanks




----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet

News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! 100,000
Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via

Encryption
=---






----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! 100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
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
Help with converting a block of cells with Absolute and mixed references to relative references Vulcan Excel Worksheet Functions 3 December 13th 07 11:43 PM
ActiveX Controls vs Form Controls Alex Excel Discussion (Misc queries) 1 January 11th 06 08:46 AM
Add controls to UserForm Vyyk Drago Excel Programming 3 August 26th 03 01:22 PM
How can I find a handle number of controls on Userform? sjoo Excel Programming 1 August 4th 03 10:21 AM
What order does VBA look at userform controls? Brad Patterson Excel Programming 3 July 17th 03 03:46 AM


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