Trying to create controls dynamically at run time.

itmasterw

Registered User.
Local time
Today, 06:01
Joined
Oct 31, 2005
Messages
45
Hi,
I have an Access 2003 application that I am developing, and need to create controls based on what a user selects in a list box. So, if the list box has three entries and the the user picks number 2, I need to create two text boxes. If they pick three then create three boxes. I did this along time agoe but I can not rember what I did fully. can someone please tell me what I am missing.
Thank you

Here is what I have so far:

Dim ctlText As Control
Dim intDataX As Single
Dim intDataY As Single

intDataX = 0.375
intDataY = 9.4167
Set ctlText = CreateControl("CONTRACTS", acTextBox, , "", "", intDataX, intDataY)
 
Do you have to create them at run time? Why not just have them on the form already with the Visible property set to No and then make them Visible as you need them?

I have never created controls at run time so I can't directly answer your question. I always do what I suggested above and then move them around and set properties as necessary.
 
itmasterw

pdx_man is right. You do not want to create the controls at run-time.
Don't know Access 2003, but all prior versions have a finite limit to the
number of objects (700+) that may be created during the LIFETIME of
the form. Once that limit is reached, your form is dead.

Much better to have then exist, then make them visible, move them,
whatever at run-time.

Wayne
 
Wayne,
I didn't know that about forms. Is that recovered with a decompile?
 
Not according to what I've seen of the MS documentation. In order to get it back I believe you have to import everything into a new, blank database.
 
I've played with this before. I wrote an application that creates a form dynamically and adds a number of controls based on the data available for an object, but the form must be in design view. An advantage you have when doing this is that the CreateForm method allows you to specify a template form which can contain controls, headers, or other form design elements, and control numbering is restarted with each CreateForm. A disadvantage, if I remember correctly, is that code in the template is not transferred to the Create(d)Form.

I agree with pdx and Wayne. I'd put hidden controls on the form and show/hide them as needed.
 

Users who are viewing this thread

Back
Top Bottom