Full Version: Maximum Number Of Controls On A Form
UtterAccess Forums > Microsoft® Access > Access Forms
ace
I am using Access 2010 to update a database that was created with Access 2003. The database
will continue to be run using Access 2003.
Everything I have read, including the Access help file itself, indicates that the maximum number
of controls that can be placed on a form over the lifetime of the form is 754.
I currently have a form with 928 label controls on it that I am using in a subform on a form
that has 60 controls on it. The 928 labels were created via VBA. The 60 controls were
placed by hand.
The form works just fine. Why?
vtd
Not sure but does your code actually save the Form with 928 Controls?
The limit may be is the saved Design of the Form???
missinglinq
Putting aside the question of where you'd put 928 Labels, exactly how/why would Access 'create' that many on one Form? The only time Access 'creates' Labels is when they are attached to other Controls. And what could possibly be the purpose of this many Labels?
Are you, perhaps, looking at a Form in something other than Single View and adding up the number of Labels/Controls?
Linq ;0)>
vtd
I am sure you can have unlinked Label Controls, i.e. Labels that are independent from other Controls...
ace
The form(s) in question make up a custom Schedule Grid.
The labels are stand alone, not attached to other controls. Labels are being used because
they provide an OnClick event and a Caption property and that is all that is needed.
The resulting Schedule grid is up and running just fine using Access 2010. I have never
owned Access 2003 so I can't test it in that version.
The conundrum is why? It apparently should not be possible.
The code used to create the labels is:
CODE
Public Sub CreateLabels()
  
  Dim targetForm As String
  Dim i As Integer
  Dim j As Integer
  Dim topPosition As Single
  Dim leftPosition As Single
  Dim groupWidth As Single
  Dim mycontrol As Object
  Dim ctrl_am As Access.Label
  
  targetForm = "form1"
  leftPosition = 0.2917 * twips
  groupWidth = 1.2917 * twips
  
  For j = 0 To 31
  
  topPosition = topPosition + 360
  Set mycontrol = CreateControl(targetForm, acLabel, acDetail)
    
  With mycontrol
    .Name = "group" & (j + 1)
    .Caption = .Name
    .Top = topPosition
    .Width = groupWidth
    .Height = 0.25 * twips
    .BackStyle = 1
    .BorderStyle = 1
    .BorderColor = RGB(0, 0, 0)
    .ForeColor = RGB(0, 0, 0)
    .BackColor = 16777215
    .FontName = "Calibri (Detail)"
  End With
  
  For i = 1 To 28
    Set mycontrol = CreateControl(targetForm, acLabel, acDetail)
  
    With mycontrol
    
      .Name = "r" & j + 1 & "d" & i
    
     .Caption = .Name
     .Width = 0.6667 * twips
     .Height = 0.25 * twips
     .Top = topPosition
     If i = 1 Then
       .Left = groupWidth
     ElseIf i = 2 Then
       .Left = leftPosition + (i * (groupWidth - .Width))
     Else
       .Left = leftPosition + (i * .Width)
     End If
     .BackStyle = 1
     .BorderStyle = 1
     .BorderColor = RGB(0, 0, 0)
     .ForeColor = RGB(0, 0, 0)
     .BackColor = 16777215
     .FontName = "Calibri (Detail)"
    End With
  Next i
  Next j
  
End Sub
ace
Are you, perhaps, looking at a Form in something other than Single View and adding up the number of Labels/Controls?

The number of controls is verified using Debug.Print Me.Controls.Count in the Open event of the form with the 928 label
controls on it.
databaselarry
Ace, and or anyone that might know......
I am sorry if this is not a good place to ask but here goes. I am using Ace's above code in access 2010 to try and create controls via VBA but when I try to open the form I get the following error
RunTime Error 6062
You must be in Disign or Layout view to create or delete controls.
Am I doing something wrong?
any and all input appreciated
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.