ACC97: Value Returned by Count Property Is Incorrect for Controls Collection (278303)



The information in this article applies to:

  • Microsoft Access 97

This article was previously published under Q278303
Advanced: Requires expert coding, interoperability, and multiuser skills.

SYMPTOMS

When you use the Count property of the Controls collection in a specific section of a Microsoft Access 97 form or report, the Count property returns a value of zero (0), even when there may be one or more controls in the specific form section.

CAUSE

You are running Microsoft Access 97 on a Microsoft Windows NT 4.0-based, Microsoft Windows 2000-based, or a Microsoft Windows XP-based computer.

STATUS

This problem was corrected in Access 2000.

MORE INFORMATION

The Count property returns a correct value when it enumerates all the controls on the overall form or report. However, the Count property returns zero when it enumerates a specific section of the form or report.

This problem does not occur in Access 97 if you are running Microsoft Windows 95, Microsoft Windows 98, or Microsoft Windows Millennium Edition (Me). The problem occurs only in a Windows NT environment or in a Windows XP environment. The problem does not occur in Microsoft Access 2000 on any version of Windows.

Steps to Reproduce the Behavior

  1. Open the Northwind sample database.
  2. In the Database window, click the Forms tab, right-click the Customer Phone List form, and then click Design. Note the controls that are in each of the sections of the form.
  3. On the View menu, click Code, and then add the following code to the form:
    Option Compare Database
    Option Explicit
    
    Private Sub Form_Load()
        Dim strPrompt As String
        Dim strTitle As String
        Dim intBtns As Integer
        Dim intRetVal As Integer
        
        strPrompt = "This form contains a total of " & Me.Controls.Count & _ 
                    " controls." & vbCrLf & "The number of controls " & _
                    "per section are as follows:" & vbCrLf & vbCrLf & _
                    "Form Header: " & Me.FormHeader.Controls.Count & vbCrLf & _
                    "Page Header: " & Me.PageHeader.Controls.Count & vbCrLf & _
                    "Detail: " & Me.Detail.Controls.Count & vbCrLf & _
                    "Page Footer: " & Me.PageFooter.Controls.Count & vbCrLf & _
                    "Form Footer: " & Me.FormFooter.Controls.Count
        intBtns = vbApplicationModal + vbInformation + vbOKOnly
        strTitle = "Control Count"
        
        intRetVal = MsgBox(strPrompt, intBtns, strTitle)
    End Sub
    						
  4. Close the class module, close the form, and when you are prompted to save the changes, click Yes.
  5. Double-click the Customer Phone List form. Note that if you are running Windows 95, Windows 98, or Windows Millennium Edition, you receive a message box with output as follows:
        This form contains a total of 46 controls.
        The number of controls per section are as follows:
    
        Form Header: 4
        Page Header: 7
        Detail: 4
        Page Footer: 3
        Form Footer: 28
    						
    If you are running Windows NT or Windows 2000, the output is as follows:
        This form contains a total of 46 controls.
        The number of controls per section are as follows:
    
        Form Header: 0
        Page Header: 0
        Detail: 0
        Page Footer: 0
        Form Footer: 0
    						

Modification Type:MajorLast Reviewed:9/27/2003
Keywords:kbprb KB278303