Code:
intCountNumber = objRecord.Fields.Count
Example:
' Purpose: The
Count property obtains the number of objects in each collection, and
sets
' the upper limit for loops that enumerate these collections.
Sub CountProperty()
On Error GoTo ErrorHandler
' Recordset
and Connection variables
Dim cnn As ADODB.Connection
Dim rst As New ADODB.Recordset
Dim strSQL As String
Dim strConnection As String
Dim intLoop As Integer
' Open a connection
Set cnn = New ADODB.Connection
strConnection = "Provider='Microsoft.Jet.OLEDB.4.0';" & _
"Data Source=D:\MyData\Northwind.mdb;"
cnn.Open strConnection
' Open recordset with
data from 'Employees' table
strSQL = "Employees"
rst.Open strSQL, cnn, adOpenForwardOnly, adLockReadOnly, adCmdTable
' Print information
about Fields collection
Debug.Print rst.Fields.Count & " Fields in Employees"
For intLoop = 0 To rst.Fields.Count - 1
Debug.Print " " & rst.Fields(intLoop).Name
Next intLoop
' Print information
about Properties collection
Debug.Print rst.Properties.Count & " Properties in Employees"
For intLoop = 0 To rst.Properties.Count
- 1
Debug.Print " " & rst.Properties(intLoop).Name
Next intLoop
' Clean up objects
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
Exit Sub
ErrorHandler:
' Clean up
objects
If Not rst Is Nothing Then
If rst.State = adStateOpen Then rst.Close
End If
Set rst = Nothing
If Not cnn Is Nothing Then
If cnn.State = adStateOpen Then cnn.Close
End If
Set cnn = Nothing
If Err <> 0 Then
MsgBox Err.Source & "-->" & Err.Description, , "Error"
End If
End Sub