Generating controls on a userform


Posted by steve w on May 09, 2001 8:28 AM

This is a repost from yesterday

Can anyone help

I am creating a Print userform Wizard and I have a multi page control on the userform. So far I have three pages. What I need is to generate some controls. On the first page I have a textbox and a next button. What I need is for when the next button is pressed to generate textboxes on page2, I need there to be as many as the textbox number on page1. Then on the second page when the next button is pressed to generate Refedit boxes on page3 and have labels with the value from the text boxes from page2 to the left and also have as many as the textbox number on page1.


Thanks for any help you can provide
steve w

Posted by Dave Hawley on May 09, 2001 9:44 AM

Hi Steve


When you make a Wizard you use a UserForm with a MultiPage on it. You then place all controls on each page and then use some code like this to hide all but the first page (page 0)

Private Sub UserForm_Initialize()
Dim i As Integer
For i = 1 To Me.MultiPage1.Pages.Count - 1
Me.MultiPage1.Pages(i).Visible = False
Next
End Sub


Below the Multipage, on the UserForm itself you have your "Next" and "Back" Buttons.
The code for the "Next" button would be like:

Private Sub CommandButton1_Click()
Select Case Me.MultiPage1.Value
Case 0
Me.MultiPage1.Pages(1).Visible = True
Me.MultiPage1.Value = 1
Case 1
Me.MultiPage1.Pages(2).Visible = True
Me.MultiPage1.Value = 1
Case 2
Me.MultiPage1.Pages(3).Visible = True
Me.MultiPage1.Value = 1
End Select
End Sub


you would of course need to add some code to ensure valid entries are made.


Dave
OzGrid Business Applications

Posted by steve w on May 09, 2001 4:52 PM

Thanks dave, but how about creating textboxes and refedits automatically based on the textbox value from page1.
Thanks steve



Posted by Dave Hawley on May 10, 2001 6:04 AM


Hi Steve

here is an example of how to create an msoObject placed on a UserForm: In this case a TextBox

Private Sub CommandButton1_Click()
Dim tTextBox As MSForms.TextBox
Set tTextBox = Me.Controls.Add("Forms.TextBox.1", "TextBox1", True)
With tTextBox
.Left = 2
.Name = "TextBox1"
.Left = 10
.Top = 10
.Height = 20
.Width = 60
End With
End Sub


...But if you are creating a Wizard you are going about it the hard way. All you need to do is have all Controls and Code on your UserForm and MultiPage and use the Visible property on each control to show or hide.

Dave


OzGrid Business Applications