Control adding during run time

benjamin.weizmann

Registered User.
Local time
Today, 10:07
Joined
Aug 30, 2016
Messages
78
hi :)
I understood I can't add controls to form during run time - unless in design view.
So, I created a lot of hidden controls and during run time I make them to visible

I feel its so naïve and not optimal - like I need reboot all those controls when the form loads and return them to hidden state, when I make them visible I transform their format (size, color, position.) during run time etc...all this take memory and time.
in addition, I don't know how much control I will need during runtime .. so do I need create massive hidden controls quantity??

I know it's very general question, but please can someone give me advice how to make it more optimal?
there is a way to create control during runtime that I don't know? is my way accepted?



Ben
 
Why exactly do you not design the form, test it, then make that form available to your "production database"? I'm not following why basic form design would change so much that you would need to modify a production form's design during production/operation.

Many developers make forms with various controls and hide/show them as needed based on program/business logic.
 
you can only create controls in design view. The accepted basis is to have some code in the form current event to hide or resize to 0,0 for the controls you do not want to be visible.

for a general function you can use the tag property for each control to indicate if is should be hidden (e.g. populate it with H)

then your code would loop through all the controls of the form - something like

Code:
dim ctrl as control
on error resume next 'in case control does not have a tag property
for each ctrl in me.controls
    ctrl.visible=ctrl.tag<>"H"
next ctrl
 
you can create control at Runtime if your
database is .accdb or .mdb (not .accde/accdr).

to create a control use

Application.CreateControl

the form must be open in design view
for this to work.
there are lots of parameters you have
to set. and its is very hard to correctly
estimate the coordinates where you
want to put them.
 
..
I feel its so naïve and not optimal - like I need reboot all those controls when the form loads and return them to hidden state, when I make them visible I transform their format (size, color, position.) during run time etc...all this take memory and time.
in addition, I don't know how much control I will need during runtime .. so do I need create massive hidden controls quantity??
..
With the computer nowadays, memory time is not a reason to keep you from having a lot of controls hidden.
Creating controls at runtime takes also time so you will not be able to notice a difference in time.
But you need to be aware of, there are some physical limitations on how wide a form can be which is approx. 57cm, so you can calculate the maximum number of controls you can have.
Another limitation is the number of controls in a form it is 754, in it's lifetime.
Lifetime is from a form is created until it is deleted.
And here is the tricky part, if you create a control and afterwards delete it, it still counts, so it you've 10 control on a form and you delete 1 control and afterwards create a new control, it counts as 11 controls.
As arnelgp writes you can create control at runtime, but it needs some VBA-skills.
 
Any reason you don't have different forms for different situations?
 
Sounds like you are using an unbound form when you should be using a bound form in datasheet or continuous view which would allow for the display of an infinite number of rows and a fixed set of columns.
 

Users who are viewing this thread

Back
Top Bottom