Ad controls dynamically

W

Wendake

Hello,
Can I create a control dynamically? I want to add some controls to a
form at run time.
Thanks.
 
D

Dirk Goldgar

Wendake said:
Hello,
Can I create a control dynamically? I want to add some controls to a form
at run time.
Thanks.


This is generally not a good idea. It's almost always a better idea to
create all the controls you anticipate ever needing at design time, and then
show, hide, and reposition the existing controls according to your needs
 
W

Wendake

OK, but...
I need to show a form similar to pivot table. In the lines I have the
tasks, in the columns the resources. I don't know how many resources I have.
In the cells I have a switch that show me if my task is started or
finished (for ex. backcolor red, yellow or green), but I need to know
also if this task interest resource A, B or N (for ex.: V1, V2, Vx).

With my cells, I want to apply function menu and click event.

Thanks.

PS: First and most important question: it's possible?



Dirk Goldgar a écrit :
 
F

fredg

Hello,
Can I create a control dynamically? I want to add some controls to a
form at run time.
Thanks.

Not a good idea.
A form has a 754 control limit (over the life of the form).
A deleted control is still counted against the 754 number allowed.

See Access help Specifications + Report and Forms

A better method is to make controls visible or not, depending upon the
situation.
 
L

Larry Linson

It is possible to dynamically create and add controls, but it is not
trivial. It's not going to be just jumping through hoops, but flaming hoops
so small that you can't avoid the flames, and I can assure you, you'll be
creating yourself a maintenance nightmare.

I have seen quite a number of "absolute requirements" for dynamically
creating controls, over the years, but when you got right down to the
"business requirements", it turned out that the only thing "absolute" was
that the developer had gotten fixated on that as a solution. The separate
(classic) VB product had a "control array" that made it easier to create new
controls, but in my experience, that was not used all that much, anyway.

In recent versions of Access, there IS a pivot table form. As you don't
explain what data you have and how it is stored, it's difficult to give you
any specific advice. And, just for the record "Access does not have
'cells'". Are you certain you meant to say "I need to know also if this task
interest resource A, B or N (for ex.: V1, V2, Vx)"? That statement makes no
sense at all to me.

Larry Linson
Microsoft Office Access MVP
 
D

David W. Fenton

It is possible to dynamically create and add controls, but it is
not trivial.

MichKa used to chime in on this subject and explain that the Access
conflict resolver didn't use dynamically created controls, but
instead started out with 255 controls and then assigned control
sources and made them visible as needed.

The reason, of course, is that a form has a maximum number of
controls that can be added to it, and once you hit that, you can't
add any more. It's 700-something if I'm remembering correctly, and
it seems to me that you'd use that up fairly quickly.
 
D

Dirk Goldgar

Wendake said:
OK, but...
I need to show a form similar to pivot table. In the lines I have the
tasks, in the columns the resources. I don't know how many resources I
have.
In the cells I have a switch that show me if my task is started or
finished (for ex. backcolor red, yellow or green), but I need to know also
if this task interest resource A, B or N (for ex.: V1, V2, Vx).

With my cells, I want to apply function menu and click event.

Thanks.

PS: First and most important question: it's possible?


I'm not following your explanation, I'm afraid. It would be theoretically
possible, I think - provided that the form is discarded -- not saved --
after each use. However, the form would have to be opened in design view,
so the code to do this couldn't be on the form itself. Maybe it could be on
another form that collects the necessary information, and then creates the
form you're talking about.

I still think it's probably a bad idea.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top