Microsoft KB Archive/278303

= ACC97: Value Returned by Count Property Is Incorrect for Controls Collection =

Article ID: 278303

Article Last Modified on 1/29/2007

-

APPLIES TO


 * Microsoft Access 97 Standard Edition

-



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
 Open the Northwind sample database. 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.  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 = &quot;This form contains a total of &quot; & Me.Controls.Count & _ &quot; controls.&quot; & vbCrLf & &quot;The number of controls &quot; & _ &quot;per section are as follows:&quot; & vbCrLf & vbCrLf & _ &quot;Form Header: &quot; & Me.FormHeader.Controls.Count & vbCrLf & _ &quot;Page Header: &quot; & Me.PageHeader.Controls.Count & vbCrLf & _ &quot;Detail: &quot; & Me.Detail.Controls.Count & vbCrLf & _ &quot;Page Footer: &quot; & Me.PageFooter.Controls.Count & vbCrLf & _ &quot;Form Footer: &quot; & Me.FormFooter.Controls.Count intBtns = vbApplicationModal + vbInformation + vbOKOnly strTitle = &quot;Control Count&quot; intRetVal = MsgBox(strPrompt, intBtns, strTitle) End Sub  Close the class module, close the form, and when you are prompted to save the changes, click Yes.  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: <pre class="fixed_text">   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: <pre class="fixed_text">   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 </li></ol>

Additional query words: prb

Keywords: kbprb KB278303

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.