This example demonstrates the Value property with Field and Property objects by displaying field and property values for the Employees table.
'BeginValueVB
Public Sub ValueX()
'To integrate this code
'replace the data source and initial catalog values
'in the connection string
' connection and recordset variables
Dim rstEmployees As ADODB.Recordset
Dim Cnxn As ADODB.Connection
Dim strCnxn As String
Dim strSQLEmployees As String
' field property variables
Dim fld As ADODB.Field
Dim prp As ADODB.Property
' Open connection
Set Cnxn = New ADODB.Connection
strCnxn = "Provider=sqloledb;Data Source=MyServer;Initial Catalog=Pubs;User Id=sa;Password=; "
Cnxn.Open strCnxn
' Open recordset with data from Employees table
Set rstEmployees = New ADODB.Recordset
strSQLEmployees = "employee"
rstEmployees.Open strSQLEmployees, Cnxn, , , adCmdTable
'rstEmployees.Open strSQLEmployees, Cnxn, adOpenStatic, adLockReadOnly, adCmdTable
' the above two lines of code are identical
Debug.Print "Field values in rstEmployees"
' Enumerate the Fields collection of the Employees table
For Each fld In rstEmployees.fields
' Because Value is the default property of a
' Field object, the use of the actual keyword
' here is optional.
Debug.Print " " & fld.Name & " = " & fld.Value
Next fld
Debug.Print "Property values in rstEmployees"
' Enumerate the Properties collection of the Recordset object
For Each prp In rstEmployees.Properties
Debug.Print " " & prp.Name & " = " & prp.Value
' because Value is the default property of a Property object
' use of the actual Value keyword is optional
Next prp
' clean up
rstEmployees.Close
Cnxn.Close
Set rstEmployees = Nothing
Set Cnxn = Nothing
End Sub
'EndValueVB
Field Object | Property Object | Value Property
© 1998-2001 Microsoft Corporation. All rights reserved.