Results 1 to 8 of 8
  1. #1
    KitesurfRob is offline Novice
    Windows 11 Access 2021
    Join Date
    Apr 2023
    Posts
    5

    CreateControl is there a maximum?

    I want to make a Form with VBA with a lot of Textboxes.
    After 31 pieces it stops with an 2100 error:

    the control element is to big for this location.

    If I make the form in Formdesign view I can make hundreds Textboxes.

    What do I do wrong?

    This is my snippet:

    Sub NewControls2()

    Dim frm As Form
    Dim ctlText As Control

    ' Create new form with tblMuziekDrager table as its record source.
    Set frm = CreateForm
    frm.RecordSource = "tblMuziekDrager"
    frm.DefaultView = 1 'Continius form

    For A = 1 To 100

    'expression.CreateControl (FormName, ControlType, Section, Parent, ColumnName, Left, Top, Width, Height)

    Set ctlText = CreateControl(frm.Name, acTextBox, , "", "", 500, A * 1000, 500, 500)

    Debug.Print "A = " & A

    Next A

    End Sub

    My Direct output:

    A = 1
    A = 2
    A = 3
    A = 4
    A = 5
    A = 6
    A = 7
    A = 8
    A = 9
    A = 10
    A = 11
    A = 12
    A = 13
    A = 14
    A = 15
    A = 16
    A = 17
    A = 18


    A = 19
    A = 20
    A = 21
    A = 22
    A = 23
    A = 24
    A = 25
    A = 26
    A = 27
    A = 28
    A = 29
    A = 30
    A = 31

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,799
    Have never needed to do this and can't imagine why I would - especially when placing 100 controls in the same location. I was going to suggest that your detail section is not large enough for more than 31 controls but if they're all stacked in the same spot then that probably isn't it. A form has a lifetime count of 255 controls I believe, but that can't be it either because you're starting with a new form each time.

    Please post code within code tags (vba button on posting toolbar) to maintain indentation and readability.

    EDIT - I played with that and see that they don't all stack in one place but it does expand the detail section to 22". I think that's the max height of a form detail section.
    Somebody dropped in on us so I have to drop this for now. I see that you handled it with "a * 1000"
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,799
    try something like
    Set ctlText = CreateControl(frm.Name, acTextBox, , "", "", 500, a * 400, 1000, 350)
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,421
    To answer your question, there is a maximum of around 700. If you create 100 controls that is 100. If you then delete them and then create another 50, that will count as a total of 150 against the 700 max i.e. the 100 deleted cannot be ‘reclaimed’

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,975
    The maximum number of controls over the lifetime of a form is 754 officially but in practice it is around 1000. See Access Specification issues (isladogs.co.uk)

    @Micron correctly identified your problem
    The maximum height of a form section is 22.75 inches (or 57.79 cm). This is also the maximum width for forms.
    The reason is that form dimensions are measured in twips where 1440 twips =1 inch.
    The maximum values are because this is an integer datatype with a maximum vale =32767 which is 22.75*1440

    If you change A*1000 to A*500, you'll get twice as many textboxes before you hit the limit
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,919
    Number of controls over lifetime of form or report is 754 https://support.microsoft.com/en-us/...8-98c1025bb47c

    Since you are creating a form 'on-the-fly' with far less than 754 controls, this should not be an issue.

    What is happening is that code tries to position 32nd control beyond the 22-inch limit of form design length.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,799
    Well at least I got one part right. Here's another way, but be warned, it will also create labels with captions. You could remove that as I was just playing around. Have never seen it necessary to to this, so the reason intrigues me. This creates 2 columns of 50 textboxes per column.
    Code:
    Sub NewControls2()
    Dim frm As Form
    Dim ctl As Control
    Dim a As Integer, i As Integer
    
    Set frm = CreateForm
    frm.RecordSource = "Sheet1"
    frm.DefaultView = 1 'Continius form
    
    For a = 1 To 50
    'create 1st column textboxes then label then assign caption
    Set ctl = CreateControl(frm.Name, acTextBox, , "", "", 1200, a * 400, 1000, 350)
    Set ctl = CreateControl(frm.Name, acLabel, , ctl.Name, , 125, a * 400, 1000, 350)
    ctl.Caption = "Textbox" & a
    
    'create 2nd column textboxes then label then assign caption
    Set ctl = CreateControl(frm.Name, acTextBox, , , , 3800, a * 400, 1000, 350)
    Set ctl = CreateControl(frm.Name, acLabel, , ctl.Name, , 2600, a * 400, 1100, 350)
    ctl.Caption = "Textbox" & (a + 50)
    
    Next a
    
    End Sub
    Last edited by Micron; 04-30-2023 at 04:10 PM. Reason: added info
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,421
    Is this in connection with your other post? If so you might want to revisit it, there are other suggestions since what you are attempting here is not a solution

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Setting A Maximum Value
    By Eranka in forum Access
    Replies: 1
    Last Post: 12-26-2017, 04:00 AM
  2. Minimum & Maximum Row Value
    By Thompyt in forum Programming
    Replies: 8
    Last Post: 05-10-2016, 01:08 PM
  3. Maximum Nos of Records
    By abusaif in forum Access
    Replies: 2
    Last Post: 11-01-2014, 08:03 AM
  4. Maximum Questions
    By data808 in forum Access
    Replies: 4
    Last Post: 01-15-2014, 12:12 PM
  5. Applications.CreateControl
    By msr71 in forum Programming
    Replies: 5
    Last Post: 04-24-2011, 09:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums