Adding controls to a form with code

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

Guest

Hello All,

Can someone please show me how to add controls (such as a checkbox) to a
form (OnOpen) for each item in a query? Or perhaps there there is a website
that explains it well?

Thanks,
 
Hi, Mike.

Unless this is a wizard or add-in that you are building, then it probably
isn't a good idea to be changing the design of forms at runtime. If controls
need to "appear" sometimes and be absent at other times, then creating all
possible controls and setting each control's Visible property or Caption
property at run-time is probably a much better idea.

That said, Access won't allow you to programmatically add a control to a
form unless the form is in design view, and Access won't let you switch to
the design view during any of the events associated with a form, like
"OnOpen." Attempting to add controls to a form "on the fly" needs to be done
from code outside of the form you wish to alter so that the alterations are
available when the form is eventually opened in form view.

If you send me your E-mail address, I can send you an Access 97 database
file that shows an example of a way to create new controls on an existing
form, and you could use the same concept to create an entirely new form and
populate the form with controls based upon your query.

One of the drawbacks to having such a "flexible" form is that your code
would be changing the design of the form, so upon closure of the altered
form, your user will always get the "Do you want to save changes to the
design of the form?" system message (and turning "SetWarnings" off doesn't
help), to which your user may easily click that "Yes" button. One way to
prevent this is to set up Access security with a workgroup file and set the
permissions to not allow regular users to modify that particular form, which
would produce yet another message telling the user that he/she doesn't have
permission to save the form. That would be a sloppy way of doing it (showing
your user two irrelevant -- in the user's view -- messages while he/she is
using the database application).

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)

- - -
When you see correct answers to your question, please sign in to Microsoft's
Online Community and mark these posts, so that all may benefit by filtering
 
Back
Top