Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2007
    Posts
    108

    Unanswered: Adding controls to form dynamically?

    I would like to add controls to MsAccess form dynamically at run-time.

    The reason I would like to do this is because I have a form with 32 rows of 14 controls that are based on records in a database. Creating 448 controls at design time and naming each textbox, button and option button individually seems too much of a task.

    Therefore I would like to use for ... next loop to create those controls and populate them based on a specific recordset.

    However, when I try to do that I get:

    "Run time error 2147. You have to be in Design view to add controls".


    SO, MY QUESTION IS:
    HOW DO I ADD CONTROLS TO MSACCESS FORM AT RUN-TIME?

    Thanks!

  2. #2
    Join Date
    Mar 2007
    Posts
    277
    MS Access forms have a lifetime limit of about 740 controls so you may want to rethink this idea. Also the number of required controls would indicate probably a Normalization issue with the tables.
    RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP, ac07, ac10 - WinXP Pro, Win7 Pro
    Please reply to this forum so all may learn.

  3. #3
    Join Date
    Apr 2007
    Posts
    108
    But can it be done?

    I don't have normalization problems, each row represents one record which is normalized imported into GUI or form to be edited by user's clicks.

  4. #4
    Join Date
    Mar 2007
    Posts
    277
    Why not just use Datasheet or Continuous Form view?
    RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP, ac07, ac10 - WinXP Pro, Win7 Pro
    Please reply to this forum so all may learn.

  5. #5
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Agreed with RG.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  6. #6
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    You could try designing a function in a module (versus in the form) and in that function, open the form in design view (using the docmd.openform "xx",acdesign) and then run your design creation code (using syntax such as Forms!MyFormName.controls....).

    Note: I may not be right about the ,acdesign. It may be a different parameter. I'm not even sure if this would work - never tried since the most controls I'll put on a form are 40-50. But that's how I'd try to do it.
    Last edited by pkstormy; 10-12-09 at 23:16.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •