Applecore Pages on Microsoft Access

Programmatically Adding Controls to a Form

If you have a Form that has a RecordSource that may be changing dynamically, and the number of fields that need to displayed will thus need to be altered, you may want to try creating extra controls on the form as they are needed. However, there are several very good reasons not to do so:
  • Controls can only be added to a Form when it is open in Design mode. This can obviously prove difficult when the form is already open;
  • As there is a limit of 754 Controls (and this figure includes labels, lines, etc.) on a Form over the lifetime of the Form, by repeatedly adding controls, and then saving the form, you will soon end up against this limit.
The solution, therefore, is not to use code to *add* the extra controls, but to instead manually add extra controls to the form, setting them to be hidden (i.e the .Visible and .Enabled properties are set to No), and then, when required, moving them to the correct position and displaying them:

Private Sub cmdShow_Click()
    Me!txtHidden.Left = 50
    Me!txtHidden.Top = 50
    Me!txtHidden.Enabled = True
    Me!txtHidden.Visible = True
End Sub

Top

 


HOME | NEW | TABLES | QUERIES | FORMS | REPORTS | GENERAL | API | DOWNLOADS | TUTORIAL | RESOURCES
E-MAIL
Copyright & Disclaimer

 

Last modified at 06/06/2006 14:54:30