Contents Index Topic Contents |
This example demonstrates the Count property with two collections in the Employee database. The property obtains the number of objects in each collection, and sets the upper limit for loops that enumerate these collections. Another way to enumerate these collections without using the Count property would be to use For Each...Next statements.
Public Sub CountX() Dim rstEmployees As ADODB.Recordset Dim strCnn As String Dim intloop As Integer ' Open recordset with data from Employee table. strCnn = "driver={SQL Server};server=srv;" & _ "uid=sa;pwd=;database=pubs" Set rstEmployees = New ADODB.Recordset rstEmployees.Open "employee", strCnn, , , adCmdTable ' Print information about Fields collection. Debug.Print rstEmployees.Fields.Count & _ " Fields in Employee" For intloop = 0 To rstEmployees.Fields.Count - 1 Debug.Print " " & rstEmployees.Fields(intloop).Name Next intloop ' Print information about Properties collection. Debug.Print rstEmployees.Properties.Count & _ " Properties in Employee" For intloop = 0 To rstEmployees.Properties.Count - 1 Debug.Print " " & rstEmployees.Properties(intloop).Name Next intloop rstEmployees.Close End Sub
Top of Page
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.