[AccessD] Form Lifetime Control Limit (Was: Advice on A2010....)

Kenneth Ismert kismert at gmail.com
Wed Dec 14 15:55:22 CST 2011


All,

I just tried another experiment:

1. In Access 2000 or later, call TestControlLifetimeLimit below (a
modification of Jim's code) to populate form controls to their limit

2. Delete some or all of the highest-numbered controls

3. Call TestControlLifetimeLimit(Forms(0)) to populate more controls.

What I found is that as long as you delete the highest-numbered controls,
the counter limit isn't enforced. I ran this until the counter got up to
17213!

Can others duplicate this?

So, my new theory is that, for some service pack of Office 2000, this got
sort-of fixed. (I recall running into this problem a decade ago in an early
release of 2000).

The maximum control limit is enforced, but the counter will keep going up,
as long as you delete some of the higher-order controls.

However, the 754-control limit will persist for forms & reports imported
from Access 97. This is why the 'rebuild from scratch' is required to
totally cure the problem in very old projects. There is simply no other way
to keep the form from inheriting the old A97 behavior.

Code:

Public Sub TestControlLifetimeLimit(Optional ByVal rObj As Object = Nothing)

    Dim rFrm As Access.Form
    Dim rText As Control
    Dim rLabel As Control
    Dim i As Integer

    On Error GoTo HandleErr

    If rObj Is Nothing Then
        Set rFrm = CreateForm()
        rFrm.HasModule = True
    ElseIf TypeOf rObj Is Access.Form Then
        Set rFrm = rObj
    ElseIf TypeOf rObj Is Access.Controls Then
        Set rFrm = rObj.Parent
    Else
        Exit Sub
    End If

    i = rFrm.Controls.Count
    Do
        Set rText = CreateControl(rFrm.Name, acTextBox, acDetail, , , (i
Mod 100) * 100, (i \ 100) * 400, 200, 200)
        Set rLabel = CreateControl(rFrm.Name, acLabel, , rText.Name, "", (i
Mod 100) * 100 + 50, (i \ 100) * 400, 200, 200)
        i = i + 1
    Loop While i < 2000

ExitHere:
    Debug.Print "Control  Count: " & rFrm.Controls.Count
    Exit Sub

HandleErr:
    Debug.Print "Error: " & Err.Number & vbCrLf & Err.Description & vbCrLf
& Err.Source
    GoTo ExitHere
End Sub

-Ken



More information about the AccessD mailing list