Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create control using Code

Status
Not open for further replies.

Kib

Programmer
May 17, 2001
58
US
Hi, I was wondering if anyone could help me, I am trying to figure out a way to create/add a control to a form in VBA. Such as a Text Box or Label, etc. So if something happens, it will add a new control to the form, and in the code give all the desired properties. Thanks.
-Kib
 
Hi!

You can not add a control to a form in form view. This means that you cannot add a control using VBA which is run, or initiated, from the form you want to add the control to. You can add a control to any form not presently open through code by first opening it in design view and using the create control function. You can then set the properties of the new control and open the form in form view.

hth
Jeff Bridgham
 
Dim ctlText As Control

Set ctlText = CreateControl(frm.Name, acTextBox, , "", "", _
intDataX, intDataY)

Works for me.

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Kib,

Can only create controls that are members of control arrays. This means that it will inherit the properties of the original control and it must inherit the code of the original.

Craig
 
Dear Kib,

you could put the desired control on the form and set its visible property to false and if you want to have it shown, you can set the visible property to true.

regards Astrid
 
I go with Sawatzky, this is what i usuall do, it get's a little messy in the design view, but it works..
Eldaria

That was my 25cent** of opinion.

** Inclusive Intrest, tax on interest, Genral tax, Enviromental tax, Tax, and tax on intrest, tax on fees, tax on tax, and other Various taxes and fees.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top