ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   UserForm Controls References (https://www.excelbanter.com/excel-programming/278770-userform-controls-references.html)

Nigel[_4_]

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 =---

Chip Pearson

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

=---



Nigel[_4_]

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 =---


All times are GMT +1. The time now is 07:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com