本范例通过显示 Employees 表的字段和属性值来演示 Field 和 Property 对象的 Value 属性。
Public Sub ValueX()
Dim rstEmployees As ADODB.Recordset Dim fldLoop As ADODB.Field Dim prpLoop As ADODB.Property Dim strCnn As String
' Open recordset with data from Employees table. strCnn = "Provider=sqloledb;" & _ "Data Source=srv;Initial Catalog=Pubs;User Id=sa;Password=; " Set rstEmployees = New ADODB.Recordset rstEmployees.Open "employee", strCnn, , , adCmdTable
Debug.Print "Field values in rstEmployees" ' Enumerate the Fields collection of the Employees ' table. For Each fldLoop In rstEmployees.Fields ' Because Value is the default property of a ' Field object, the use of the actual keyword ' here is optional. Debug.Print " " & fldLoop.Name & " = " & fldLoop.Value Next fldLoop
Debug.Print "Property values in rstEmployees" ' Enumerate the Properties collection of the ' Recordset object. For Each prpLoop In rstEmployees.Properties ' Because Value is the default property of a ' Property object, the use of the actual keyword ' here is optional. Debug.Print " " & prpLoop.Name & " = " & prpLoop.Value Next prpLoop