Full Version: Create control on the form at runtime
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
access2009eg
Why This code Not work?
I'm just learning >> I want to add text box at runtime
Dim ctl As Control
Set ctl = CreateControl(form1, acTextBox, , "", "", "", "")

thank you
pere_de_chipstick
Hi Azouzeg

I am not sure where your code is placed or the details but hope the following helps:

1. Code must not be on the form where the control is being added
2. Code format should be
Set ctltxt = CreateControl("form1", acTextBox, , , , 2000, 4000, 1000)
Where there is no parameter, it should be left blank not be (e.g.
Set ctltxt = CreateControl("form1", acTextBox, ,"" ,"" , "", "", "")
3. Form1 should be "form1" (unless form1 is a string variable and form1 = "formName")
4. You can only create a control when in design view.
Hence you will not be able to add controls in an mde database and you can't open a form in design mode if you are using MS Access Runtime.

I am not sure why you want to create a control on a form at runtime. Could you not have the control on the form with its visible property set to 'No' and then make it visible ( = Yes) when you require it?

HTH

Edited by: pere_de_chipstick on Mon May 19 17:11:21 EDT 2008.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.