Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / May 2007

Tip: Looking for answers? Try searching our database.

adding components by code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
R.Warning - 22 May 2007 07:07 GMT
Hi, is it possible to add components (like textboxes) to a form using VBA code.
I thougt it is possible with a form in design view, but I don't know how.

regards

Rob
Sergey Poberezovskiy - 22 May 2007 09:47 GMT
Sure,

Just take a look at CreateControl for form controls and CreateReportControl
for report controls respectively.

> Hi, is it possible to add components (like textboxes) to a form using VBA code.
> I thougt it is possible with a form in design view, but I don't know how.
>
> regards
>
> Rob
Klatuu - 22 May 2007 13:57 GMT
Although using the CreateControl method will do this, it is not advised.  The
problem you run into is that a form has a life time maximum of 754 controls.  
That is, if you add a control to a form, the count goes up by one, but if you
delete a control, the count does not reduce by one.  Therefore, it doesn't
take long before the form will error out and no longer work.

In a case where a control may or may not be needed at run time, the better
way is to create the control in design view and make it not Visible.  Then
when you determine you need it at run time, just make it visible.

If you think you will not know how many controls you may need, I suggest you
rethink your design.

Signature

Dave Hargis, Microsoft Access MVP

> Hi, is it possible to add components (like textboxes) to a form using VBA code.
> I thougt it is possible with a form in design view, but I don't know how.
>
> regards
>
> Rob
Sergey Poberezovskiy - 23 May 2007 02:57 GMT
Dave,

There may be legitimate scenarios where you would need to use them - for
example, creating a form/report creation Wizard for your users, or
re-creating the database from another source (as I did in my case - I
serialize the database to xml files and deserialize them back into a new
database).

> Although using the CreateControl method will do this, it is not advised.  The
> problem you run into is that a form has a life time maximum of 754 controls.  
[quoted text clipped - 15 lines]
> >
> > Rob
Klatuu - 23 May 2007 13:53 GMT
Both scenerios you describe are one time events.  My comment has to do with
creating controls at run time for a form that is used in production.  It is
never a good idea.  The form will eventually fail.
Signature

Dave Hargis, Microsoft Access MVP

> Dave,
>
[quoted text clipped - 23 lines]
> > >
> > > Rob
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.