CreateControl

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I use the CreateControl to create a new control within a form. However,
later I need to reference the newly created control. How can I name the
control after creating it or is there an input for this that I missed for
this exact purpose?

Thank you,

Daniel
 
I found my answer.

Dim ctl As Control
Set ctl = CreateControl(strDfltName, acTextBox, _
acDetail, , "Key", 100, 100, 1000, 300)
'Set Control properties
ctl.Name = "txtKey"
Set ctl = Nothing
 
Creating controls programmatically has to be done with caution. If this is a
"one time" thing to modify a form, then there should be no problem; however,
if this is a normal part of your processing, be aware there is a "Life Time"
limit of 754 controls on a form. By that, I mean that each time you add a
control, the count goes up by one, but deleteing a control does not subract
from the count. The end result is that after a period of time, your form
will no longer be usable.
 
Klatuu,

That should not present a problem for my current application (1 time deal).
However, is there a way to determine the current lifetime count of a form
through vba? Not that is crucial, but is there a reason for this limit?
There is not way to reset the lifetime counter?

Thank you for the heads up, definetly something to keep in mind. I have a
few forms that have been rework tremendously, this may end up posing a
problem down the line.

If a form get to that point, can one simply create a new form and copy over
all the controls to start anew?

Daniel
 
There's no way to determine the current lifetime count that I'm aware of,
nor any way to reset the counter (other than copying the form and creating a
new object).
 
I don't know what the reason is. It probably relates to some internal limit
Access uses to store information on the objects in the database.
I don't know if there is a way to know the lifetime count. You can find the
number of current controls if the form is open using:
Forms!TheFormName.Controls.Count

You can copy the form to a new mdb and it will loose the lifetime count.
 
Back
Top