Adding textbox to page at runtime

salvo

New Member
Joined
Nov 18, 2009
Messages
12
Hi,
I am trying to write a routine to be able to place a textbox on a multipager layout that is on a userform during program execution. I am able to place a textbox on the userform but not on the page of a userform. Below is a snippet of code i found on this forum but it only puts the text box on the form not the page sitting on the form. Thanks


Private Sub CommandButton1_Click()
Dim newtxtbox As MSforms.Control

Set newtxtbox = UserForm1.Controls.Add("Forms.Textbox.1")
With newtxtbox
.Name = "new box"
.Left = 10
.Top = 10
.Width = 50
.Height = 20
.Visible = True
End With
End sub



Any suggestions

:)

Thanks
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Adding controls at run-time is problematic, particularly when it comes to writting event code for those controls. Creating all the needed controls at design time and toggeling their Visible property at run-time is a more robust approach.

Having said that, the syntax you asked about is
Code:
Set newtxtbox = UserForm1.MultiPage1.Pages("Page1").Controls.Add("Forms.Textbox.1")
 
Last edited:
Upvote 0
salvo

I've got a suggestion - don't do/try it.:)

As Mike has said it's problematic at least and I really don't see the point of doing in the first place.:eek:
 
Upvote 0
salvo

I've got a suggestion - don't do/try it.:)

As Mike has said it's problematic at least and I really don't see the point of doing in the first place.:eek:


Norie - i would love to avoid the problem, but i have multiple input textboxes which may run into the hundreds at worst case. It all depends on what options the user picks. Apart from the laborious task of manually adding dozens of text boxes, there is also the problem of not knowing the exact amount i need until run time - so hence i figure it would be easier to code them out. I am more than happy to hear suggestions/alternatives to try and avoid the problem.

What my application is doing is taking an old fashined excel spreadsheet with plenty of user input and converting it to a polished program by putting a front end using VBA code. I figure i could write a routine that read the labels and input boxes that were on the excel spreadsheet (on 25 sheets) and put them onto a userform with multipage tabs to produce a polished program. Any suggestion for a workaround? :)
 
Upvote 0

Forum statistics

Threads
1,216,028
Messages
6,128,393
Members
449,446
Latest member
CodeCybear

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top