PC Review


Reply
Thread Tools Rate Thread

Assign values to specific Text Boxes

 
 
Phantom
Guest
Posts: n/a
 
      4th Dec 2006
Hi ~

I've been going through the archives and I can't seem to find a
solution for my problem. I have created a form ("UserForm1") that
consists of 16 text boxes, 7 labels, and 4 check boxes. I've created a
process that will populate the 16 text boxes, but I have to
individually call out each of the 16 text boxes to populate data. ex.
UserForm1.txtTextBox1.Value = "blah" and so on. Is there an easier way
to do it? I only want to search for the text boxes and then populate
them w/ my data. I'm trying to make my code as generic as possible and
I'm not sure how to accomplish that. I'm a newbie at VBA so it's
taking a while to get a handle on it. So, here are my questions:
1. Is it possible to loop through each of the text boxes and populate
them with data? For example, "For Each <TextBox> in
UserForm1.Controls....."
2. Also, is there a way to pass an array pointing to a particular text
box? Or, instead of typing the exact reference of the txtTextBox, can
I pass the reference as a paramater? For example, I would like to have
the value of "blah5" in UserForm1.txtTextBox5.Value.
This is what I have so far....
Example:
Dim myTextBox as TextBox
Dim myFormCtrl as Control

For each myFormCtrl in UserForm1.Controls
If TypeName(myFormCtrl) = "TextBox" Then
<What do I do here?>
End If
Next

I hope that I've explained the problem for you. Any help that you
could provide would be very much appreciated.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm9obiBCdW5keQ==?=
Guest
Posts: n/a
 
      4th Dec 2006
Check this out, or search for control array.

http://builder.com.com/5100-6228-5388637.html

-John

"Phantom" wrote:

> Hi ~
>
> I've been going through the archives and I can't seem to find a
> solution for my problem. I have created a form ("UserForm1") that
> consists of 16 text boxes, 7 labels, and 4 check boxes. I've created a
> process that will populate the 16 text boxes, but I have to
> individually call out each of the 16 text boxes to populate data. ex.
> UserForm1.txtTextBox1.Value = "blah" and so on. Is there an easier way
> to do it? I only want to search for the text boxes and then populate
> them w/ my data. I'm trying to make my code as generic as possible and
> I'm not sure how to accomplish that. I'm a newbie at VBA so it's
> taking a while to get a handle on it. So, here are my questions:
> 1. Is it possible to loop through each of the text boxes and populate
> them with data? For example, "For Each <TextBox> in
> UserForm1.Controls....."
> 2. Also, is there a way to pass an array pointing to a particular text
> box? Or, instead of typing the exact reference of the txtTextBox, can
> I pass the reference as a paramater? For example, I would like to have
> the value of "blah5" in UserForm1.txtTextBox5.Value.
> This is what I have so far....
> Example:
> Dim myTextBox as TextBox
> Dim myFormCtrl as Control
>
> For each myFormCtrl in UserForm1.Controls
> If TypeName(myFormCtrl) = "TextBox" Then
> <What do I do here?>
> End If
> Next
>
> I hope that I've explained the problem for you. Any help that you
> could provide would be very much appreciated.
>
>

 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      4th Dec 2006
You could use code like

Dim Ctrl As MSForms.Control
For Each Ctrl In Userform1.Controls
If TypeOf Ctrl Is MSForms.TextBox Then
' do something with Ctrl
End If
Next Ctrl


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)


"Phantom" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi ~
>
> I've been going through the archives and I can't seem to find a
> solution for my problem. I have created a form ("UserForm1") that
> consists of 16 text boxes, 7 labels, and 4 check boxes. I've created a
> process that will populate the 16 text boxes, but I have to
> individually call out each of the 16 text boxes to populate data. ex.
> UserForm1.txtTextBox1.Value = "blah" and so on. Is there an easier way
> to do it? I only want to search for the text boxes and then populate
> them w/ my data. I'm trying to make my code as generic as possible and
> I'm not sure how to accomplish that. I'm a newbie at VBA so it's
> taking a while to get a handle on it. So, here are my questions:
> 1. Is it possible to loop through each of the text boxes and populate
> them with data? For example, "For Each <TextBox> in
> UserForm1.Controls....."
> 2. Also, is there a way to pass an array pointing to a particular text
> box? Or, instead of typing the exact reference of the txtTextBox, can
> I pass the reference as a paramater? For example, I would like to have
> the value of "blah5" in UserForm1.txtTextBox5.Value.
> This is what I have so far....
> Example:
> Dim myTextBox as TextBox
> Dim myFormCtrl as Control
>
> For each myFormCtrl in UserForm1.Controls
> If TypeName(myFormCtrl) = "TextBox" Then
> <What do I do here?>
> End If
> Next
>
> I hope that I've explained the problem for you. Any help that you
> could provide would be very much appreciated.
>



 
Reply With Quote
 
Jon Peltier
Guest
Posts: n/a
 
      4th Dec 2006
VBA doesn't have control arrays, although you can set up a class module to
handle events from a group of controls:

Handle Multiple UserForm Buttons With One Procedure
http://www.j-walk.com/ss/excel/tips/tip44.htm

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"John Bundy" <(E-Mail Removed)> wrote in message
news:4DEFFB0C-F7A5-49D4-8242-(E-Mail Removed)...
> Check this out, or search for control array.
>
> http://builder.com.com/5100-6228-5388637.html
>
> -John
>
> "Phantom" wrote:
>
>> Hi ~
>>
>> I've been going through the archives and I can't seem to find a
>> solution for my problem. I have created a form ("UserForm1") that
>> consists of 16 text boxes, 7 labels, and 4 check boxes. I've created a
>> process that will populate the 16 text boxes, but I have to
>> individually call out each of the 16 text boxes to populate data. ex.
>> UserForm1.txtTextBox1.Value = "blah" and so on. Is there an easier way
>> to do it? I only want to search for the text boxes and then populate
>> them w/ my data. I'm trying to make my code as generic as possible and
>> I'm not sure how to accomplish that. I'm a newbie at VBA so it's
>> taking a while to get a handle on it. So, here are my questions:
>> 1. Is it possible to loop through each of the text boxes and populate
>> them with data? For example, "For Each <TextBox> in
>> UserForm1.Controls....."
>> 2. Also, is there a way to pass an array pointing to a particular text
>> box? Or, instead of typing the exact reference of the txtTextBox, can
>> I pass the reference as a paramater? For example, I would like to have
>> the value of "blah5" in UserForm1.txtTextBox5.Value.
>> This is what I have so far....
>> Example:
>> Dim myTextBox as TextBox
>> Dim myFormCtrl as Control
>>
>> For each myFormCtrl in UserForm1.Controls
>> If TypeName(myFormCtrl) = "TextBox" Then
>> <What do I do here?>
>> End If
>> Next
>>
>> I hope that I've explained the problem for you. Any help that you
>> could provide would be very much appreciated.
>>
>>



 
Reply With Quote
 
=?Utf-8?B?Sm9obiBCdW5keQ==?=
Guest
Posts: n/a
 
      4th Dec 2006
Sorry, he's right of course, Ive been working in VB6.

"Jon Peltier" wrote:

> VBA doesn't have control arrays, although you can set up a class module to
> handle events from a group of controls:
>
> Handle Multiple UserForm Buttons With One Procedure
> http://www.j-walk.com/ss/excel/tips/tip44.htm
>
> - Jon
> -------
> Jon Peltier, Microsoft Excel MVP
> Tutorials and Custom Solutions
> http://PeltierTech.com
> _______
>
>
> "John Bundy" <(E-Mail Removed)> wrote in message
> news:4DEFFB0C-F7A5-49D4-8242-(E-Mail Removed)...
> > Check this out, or search for control array.
> >
> > http://builder.com.com/5100-6228-5388637.html
> >
> > -John
> >
> > "Phantom" wrote:
> >
> >> Hi ~
> >>
> >> I've been going through the archives and I can't seem to find a
> >> solution for my problem. I have created a form ("UserForm1") that
> >> consists of 16 text boxes, 7 labels, and 4 check boxes. I've created a
> >> process that will populate the 16 text boxes, but I have to
> >> individually call out each of the 16 text boxes to populate data. ex.
> >> UserForm1.txtTextBox1.Value = "blah" and so on. Is there an easier way
> >> to do it? I only want to search for the text boxes and then populate
> >> them w/ my data. I'm trying to make my code as generic as possible and
> >> I'm not sure how to accomplish that. I'm a newbie at VBA so it's
> >> taking a while to get a handle on it. So, here are my questions:
> >> 1. Is it possible to loop through each of the text boxes and populate
> >> them with data? For example, "For Each <TextBox> in
> >> UserForm1.Controls....."
> >> 2. Also, is there a way to pass an array pointing to a particular text
> >> box? Or, instead of typing the exact reference of the txtTextBox, can
> >> I pass the reference as a paramater? For example, I would like to have
> >> the value of "blah5" in UserForm1.txtTextBox5.Value.
> >> This is what I have so far....
> >> Example:
> >> Dim myTextBox as TextBox
> >> Dim myFormCtrl as Control
> >>
> >> For each myFormCtrl in UserForm1.Controls
> >> If TypeName(myFormCtrl) = "TextBox" Then
> >> <What do I do here?>
> >> End If
> >> Next
> >>
> >> I hope that I've explained the problem for you. Any help that you
> >> could provide would be very much appreciated.
> >>
> >>

>
>
>

 
Reply With Quote
 
Phantom
Guest
Posts: n/a
 
      7th Dec 2006
Hi guys ~

thanks so much for all your help. I ended up going with Jon Peltier's
suggestion. Thanks to everyone to responded. I really appreciate the
help. My code works fine now.

On Dec 4, 4:06 pm, John Bundy <JohnBu...@discussions.microsoft.com>
wrote:
> Sorry, he's right of course, Ive been working in VB6.
>
> "Jon Peltier" wrote:
> > VBA doesn't have control arrays, although you can set up a class module to
> > handle events from a group of controls:

>
> > Handle Multiple UserForm Buttons With One Procedure
> > http://www.j-walk.com/ss/excel/tips/tip44.htm

>
> > - Jon
> > -------
> > Jon Peltier, Microsoft Excel MVP
> > Tutorials and Custom Solutions
> >http://PeltierTech.com
> > _______

>
> > "John Bundy" <JohnBu...@discussions.microsoft.com> wrote in message
> >news:4DEFFB0C-F7A5-49D4-8242-(E-Mail Removed)...
> > > Check this out, or search for control array.

>
> > >http://builder.com.com/5100-6228-5388637.html

>
> > > -John

>
> > > "Phantom" wrote:

>
> > >> Hi ~

>
> > >> I've been going through the archives and I can't seem to find a
> > >> solution for my problem. I have created a form ("UserForm1") that
> > >> consists of 16textboxes, 7 labels, and 4 checkboxes. I've created a
> > >> process that will populate the 16textboxes, but I have to
> > >> individually call out each of the 16textboxesto populate data. ex.
> > >> UserForm1.txtTextBox1.Value = "blah" and so on. Is there an easier way
> > >> to do it? I only want to search for thetextboxesand then populate
> > >> them w/ my data. I'm trying to make my code as generic as possible and
> > >> I'm not sure how to accomplish that. I'm a newbie at VBA so it's
> > >> taking a while to get a handle on it. So, here are my questions:
> > >> 1. Is it possible to loop through each of thetextboxesand populate
> > >> them with data? For example, "For Each <TextBox> in
> > >> UserForm1.Controls....."
> > >> 2. Also, is there a way to pass an array pointing to a particulartext
> > >> box? Or, instead of typing the exact reference of the txtTextBox, can
> > >> I pass the reference as a paramater? For example, I would like to have
> > >> the value of "blah5" in UserForm1.txtTextBox5.Value.
> > >> This is what I have so far....
> > >> Example:
> > >> Dim myTextBox as TextBox
> > >> Dim myFormCtrl as Control

>
> > >> For each myFormCtrl in UserForm1.Controls
> > >> If TypeName(myFormCtrl) = "TextBox" Then
> > >> <What do I do here?>
> > >> End If
> > >> Next

>
> > >> I hope that I've explained the problem for you. Any help that you
> > >> could provide would be very much appreciated.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to add fields and text boxes and assign control source to the. SuperNerd Microsoft Access VBA Modules 1 19th Sep 2008 06:16 PM
assign values to specific cells in an excel sheet through text file s_pushparaj Microsoft Excel Misc 2 11th May 2008 10:09 PM
Re: Assign Values to text cells T. Valko Microsoft Excel Misc 0 15th Jan 2007 09:45 PM
Assign values to text =?Utf-8?B?VG93biBvZiBFeGV0ZXI=?= Microsoft Excel Worksheet Functions 0 17th Aug 2005 01:47 PM
Assign values to text within a cell =?Utf-8?B?Qm9i?= Microsoft Excel Worksheet Functions 2 7th Jun 2005 09:51 PM


Features
 

Advertising
 

Newsgroups
 


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