PC Review


Reply
Thread Tools Rate Thread

Automatically add a textbox to a user form based on user requireme

 
 
=?Utf-8?B?QnJpdGU=?=
Guest
Posts: n/a
 
      7th Apr 2007
I was wondering if it is possible to automatically add a text box to a user
form based on user requirements?

I'm trying to make a wizard, and the way i want it to work is:

1. A userform will appear asking how many sources of revenue the user would
like to enter.

2. On the next userform i want the appropriate number of text boxes to
appear so that the user can enter all of their data. For example. Say a user
enters that they would want to enter 3 sources of revenue. On the next screen
i want a user form to appear with three textboxes so that they can enter all
of their data.

Is there a way to do this?

thanks in advance for your help!

 
Reply With Quote
 
 
 
 
Helmut Weber
Guest
Posts: n/a
 
      7th Apr 2007
Hi Brite,

populate the second userform with as many textboxes
as a value from the first userform returns:

Private Sub UserForm_Click()

Dim l As Long
UserForm1.Hide
For l = 1 To Me.TextBox1.Value
Set obj = UserForm2.Controls.Add("Forms.TextBox.1")
If l = 1 Then
obj.Top = 20
Else
obj.Top = l * 20
End If
Next
UserForm2.Show
End Sub


Adjusting the size of the userform2 is another matter,
and controlling where and in what size the textboxes shall appear.

Just to show that it is possible.
There is a lot more to it.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"


 
Reply With Quote
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      7th Apr 2007
Here's one way to do it. Paste this sub routine in your form code module:

Private Sub AddTextBox(iCount As Integer)
Dim i As Integer
For i = 1 To iCount
Me.Controls.Add "Forms.TextBox.1", "txtBox" & i, True
'adjust the textbox position as needed
With Me.Controls("txtBox" & i)
'10 pixes from the left edge of the form
.Left = 10
'20 pixes from the top of the form,
'2 pixels between each text box
.Top = (i * (.Height + 2)) + 20
End With

Next i
End Sub

Call it in your form by:

AddTextBox 3


--
Hope that helps.

Vergel Adriano


"Brite" wrote:

> I was wondering if it is possible to automatically add a text box to a user
> form based on user requirements?
>
> I'm trying to make a wizard, and the way i want it to work is:
>
> 1. A userform will appear asking how many sources of revenue the user would
> like to enter.
>
> 2. On the next userform i want the appropriate number of text boxes to
> appear so that the user can enter all of their data. For example. Say a user
> enters that they would want to enter 3 sources of revenue. On the next screen
> i want a user form to appear with three textboxes so that they can enter all
> of their data.
>
> Is there a way to do this?
>
> thanks in advance for your help!
>

 
Reply With Quote
 
=?Utf-8?B?QnJpdGU=?=
Guest
Posts: n/a
 
      7th Apr 2007
This is great, thanks very much for both of your responses!

"Vergel Adriano" wrote:

> Here's one way to do it. Paste this sub routine in your form code module:
>
> Private Sub AddTextBox(iCount As Integer)
> Dim i As Integer
> For i = 1 To iCount
> Me.Controls.Add "Forms.TextBox.1", "txtBox" & i, True
> 'adjust the textbox position as needed
> With Me.Controls("txtBox" & i)
> '10 pixes from the left edge of the form
> .Left = 10
> '20 pixes from the top of the form,
> '2 pixels between each text box
> .Top = (i * (.Height + 2)) + 20
> End With
>
> Next i
> End Sub
>
> Call it in your form by:
>
> AddTextBox 3
>
>
> --
> Hope that helps.
>
> Vergel Adriano
>
>
> "Brite" wrote:
>
> > I was wondering if it is possible to automatically add a text box to a user
> > form based on user requirements?
> >
> > I'm trying to make a wizard, and the way i want it to work is:
> >
> > 1. A userform will appear asking how many sources of revenue the user would
> > like to enter.
> >
> > 2. On the next userform i want the appropriate number of text boxes to
> > appear so that the user can enter all of their data. For example. Say a user
> > enters that they would want to enter 3 sources of revenue. On the next screen
> > i want a user form to appear with three textboxes so that they can enter all
> > of their data.
> >
> > Is there a way to do this?
> >
> > thanks in advance for your help!
> >

 
Reply With Quote
 
Jon Peltier
Guest
Posts: n/a
 
      7th Apr 2007
I prefer putting my controls on the userform during design time, so I know
how the form will look. I keep certain ones hidden, then show them (rather
than drawing new ones) when needed.

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


"Brite" <(E-Mail Removed)> wrote in message
news:CCFC3904-26A3-4512-927C-(E-Mail Removed)...
>I was wondering if it is possible to automatically add a text box to a user
> form based on user requirements?
>
> I'm trying to make a wizard, and the way i want it to work is:
>
> 1. A userform will appear asking how many sources of revenue the user
> would
> like to enter.
>
> 2. On the next userform i want the appropriate number of text boxes to
> appear so that the user can enter all of their data. For example. Say a
> user
> enters that they would want to enter 3 sources of revenue. On the next
> screen
> i want a user form to appear with three textboxes so that they can enter
> all
> of their data.
>
> Is there a way to do this?
>
> thanks in advance for your help!
>



 
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
Textbox in user form =?Utf-8?B?Q3VydA==?= Microsoft Excel Programming 2 20th Feb 2007 12:45 AM
Send workbook automatically as attachment based on input from user =?Utf-8?B?U29ueQ==?= Microsoft Excel Programming 6 3rd Oct 2006 02:41 PM
Automatically populate date/time based on user entry Timothy.Rybak@gmail.com Microsoft Access 2 16th Aug 2006 01:57 PM
textbox on user form =?Utf-8?B?TWlrZQ==?= Microsoft Excel Programming 3 2nd Dec 2005 04:43 PM
User Form in VB = TextBox =?Utf-8?B?S2Vs?= Microsoft Excel Misc 1 11th Aug 2005 12:26 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:01 AM.