Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default How to iterate through all Text Boxes on a Form?

I can iterate through all the controls on a UserForm, but I can't find a
"Type" or other property that will let me get just the Text Boxes. Any
help?

Ed


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default How to iterate through all Text Boxes on a Form?

Hi Ed

Put them into your own new custom collection like this:

Option Explicit

Dim MyTextBoxes As Collection

Private Sub UserForm_Initialize()
Set MyTextBoxes = New Collection
MyTextBoxes.Add Me.TextBox1, "T1"
MyTextBoxes.Add Me.TextBox2, "T2"
MyTextBoxes.Add Me.TextBox3, "T3"
End Sub

Private Sub CommandButton1_Click()
Dim TB As MSForms.TextBox
For Each TB In MyTextBoxes
MsgBox TB.Text
Next
MsgBox MyTextBoxes("T2").Text
MsgBox MyTextBoxes(1).Text
End Sub

HTH. Best wishes Harald

"Ed" skrev i melding
...
I can iterate through all the controls on a UserForm, but I can't find a
"Type" or other property that will let me get just the Text Boxes. Any
help?

Ed




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How to iterate through all Text Boxes on a Form?

for each ctrl in Userform1.controls
if typeof ctrl is MSForms.Textbox then
ctrl.Value = ""
end if
Next

--
Regards,
Tom Ogilvy

"Ed" wrote in message
...
I can iterate through all the controls on a UserForm, but I can't find a
"Type" or other property that will let me get just the Text Boxes. Any
help?

Ed




  #4   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default How to iterate through all Text Boxes on a Form?

Wow! You've helped quite a bit today alone, Tom. Hope some day I can
return the favor.

Thank you!
Ed

"Tom Ogilvy" wrote in message
...
for each ctrl in Userform1.controls
if typeof ctrl is MSForms.Textbox then
ctrl.Value = ""
end if
Next

--
Regards,
Tom Ogilvy

"Ed" wrote in message
...
I can iterate through all the controls on a UserForm, but I can't find a
"Type" or other property that will let me get just the Text Boxes. Any
help?

Ed






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 292
Default How to iterate through all Text Boxes on a Form?

Hi Tom

This is probably only a theoretical problem, but code that loops all
controls might loop and test 200+ of them every time just to get something
done to 5 of them.

Best wishes Harald

"Tom Ogilvy" skrev i melding
...
for each ctrl in Userform1.controls
if typeof ctrl is MSForms.Textbox then
ctrl.Value = ""
end if
Next





  #6   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default How to iterate through all Text Boxes on a Form?

Harald - I didn't think of that. At the moment, I don't have that problem.
Later on, though (assuming I get good enough that people want more
complicated stuff), that can become a problem. I will look into the custom
collections - that has definite possibilities.

Thanks.
Ed

"Harald Staff" wrote in message
...
Hi Tom

This is probably only a theoretical problem, but code that loops all
controls might loop and test 200+ of them every time just to get something
done to 5 of them.

Best wishes Harald

"Tom Ogilvy" skrev i melding
...
for each ctrl in Userform1.controls
if typeof ctrl is MSForms.Textbox then
ctrl.Value = ""
end if
Next





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
Link Text Boxes on Form? Joyce Excel Discussion (Misc queries) 8 September 1st 09 06:20 AM
User Form Text Boxes - Copy format of text boxes NDBC Excel Discussion (Misc queries) 3 July 2nd 09 02:02 AM
Form Text Boxes moving md2503 Excel Worksheet Functions 2 May 16th 05 07:57 PM
Newbie question: How to iterate over combo boxes on a worksheet Mark Shirley Excel Programming 0 November 2nd 04 05:28 AM
Numerical accuracy in Form Text-boxes steve Excel Programming 2 August 23rd 03 02:34 AM


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