Results 1 to 6 of 6
  1. #1
    Star Lounger
    Join Date
    Jan 2003
    Location
    Grass Valley, California, USA
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Dynamic Controls on a Form (2000)

    I have a situation where I need to have a two-dimensional matrix of label controls on a form that can be dynamically assigned captions, selectively enabled and disabled, and respond to Click Events when enabled. The matrix is currently 60 rows, and 9 columns. But that is more template than absolute. Depending upon table data, I might need as many as 96 rows, or as few as 24 rows. The column count could vary from as few as two columns to as many as 20 or more.

    Currently, I have manually built my 60 x 9 matrix in the form design window. With some careful VBA coding, I can trim the usable portion of the matrix to something less than that defined (using a combination of dynamic settings for control width, height , left & top settings, as well as visibility). However, it would be much more appealing if I could start with "a blank slate (form)" and dynamically add the label controls as needed; likewise, dynamically delete them as conditions change.

    I've looked fairly extensively at the help screens, as well as the Microsoft Office 2000 Visual Basic Programmer's Guide. I can find no description of how to accomplish any programmatic add/delete of form controls.

    Does anyone know if this feature is possible? And if so, where I can get details and/or examples of such actions?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Dynamic Controls on a Form (2000)

    You need the CreateControl method. Open the Visual Basic Editor, activate the Immediate window (Ctrl+G), type CreateControl and press F1. You'll get a description with an example.

    Note: be very careful, the total number of controls on a form is 754 during its entire lifetime. This means that once you have created 754 controls, you won't be able to create any new ones on that form, even if you delete some or all of the existing controls. So with 96 rows, you can't create more than 7 colums, and with 20 columns, you can't create more than 37 rows. This limitation is fixed and has been present in all versions of Access, as far as I know; there is no setting to extend the limit.

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Dynamic Controls on a Form (2000)

    Why not just hide the controls you don't need and set the captions of the visible controls in code rather than trying to delete and create? This is essentially what the switchboards built with the switchboard manager do and you could study that approach and adapt it to your needs. The code to set the captions is much simpler than the code to create controls.
    Charlotte

  4. #4
    Star Lounger
    Join Date
    Jan 2003
    Location
    Grass Valley, California, USA
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Dynamic Controls on a Form (2000)

    Hans,
    Thanks. The CreateControl method sounds like exactly the tool I'm seeking. I'll study-up on it today.
    -- Jim

  5. #5
    Star Lounger
    Join Date
    Jan 2003
    Location
    Grass Valley, California, USA
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Dynamic Controls on a Form (2000)

    Charlotte,
    Thanks for your suggestion. However, while your technique certainly can work (I'm doing that now!), the manual labor involved in creating a form with 500 to 700 controls, each with its own special location, name, etc., takes MUCH longer than you might imagine. Certainly longer than what can be done with a few FOR loops....
    -- Jim

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Dynamic Controls on a Form (2000)

    If you have 700 controls, you will not be able to use the CreateControl method more than once before you trip over the limit. Hiding controls and changing labels is much faster than creating new controls, and doesn't run into the limit on controls created, which includes *all* kinds of controls including graphics. I wasn't suggesting a few FOR loops, I was suggesting a table-driven form. I have a very good imagination when it comes to the time it takes to execute code since I make my living as an Access developer. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    Charlotte

Posting Permissions

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