Value Property

Applies To   Field object, Parameter object, Property object.

Description

Sets or returns the value of an object.

Settings and Return Values

The setting or return value is a Variant data type that evaluates to a value appropriate for the data type, as specified by the Type property of an object.

Remarks

Generally, the Value property is used to retrieve and alter data in Recordset objects.

The Value property is the default property of the Field, Parameter, and Property objects. Therefore, you can set or return the value of one of these objects by referring to them directly instead of specifying the Value property.

Trying to set or return the Value property in an inappropriate context (for example, the Value property of a Field object in the Fields collection of a TableDef object) will cause a trappable error.

Notes

  • In an ODBCDirect workspace, you cannot read or set the Value property of a Recordset field more than once without refreshing the current record. For example, to read and then set the Value property, first read the property, then use the Move 0 method to refresh the current record, then write the new value.
  • When reading decimal values from a Microsoft SQL Server database, they will be formatted using scientific notation through a Microsoft Jet workspace, but will appear as normal decimal values through an ODBCDirect workspace.
See Also

Name property, Updatable property.

Example

This example demonstrates the Value property with Field and Property objects.

Sub ValueX()

    Dim dbsNorthwind As Database
    Dim rstEmployees As Recordset
    Dim fldLoop As Field
    Dim prpLoop As Property

    Set dbsNorthwind = OpenDatabase("Northwind.mdb")
    Set rstEmployees = _
        dbsNorthwind.OpenRecordset("Employees")

    With rstEmployees
        Debug.Print "Field values in rstEmployees"
        ' Enumerate the Fields collection of the Employees
        ' table.
        For Each fldLoop In .Fields
            Debug.Print "    " & fldLoop.Name & " = ";
            Select Case fldLoop.Type
                Case dbLongBinary
                    Debug.Print "[LongBinary]"
                Case dbMemo
                    Debug.Print "[Memo]"
                Case Else
                    ' Because Value is the default property of a
                    ' Field object, the use of the actual keyword
                    ' here is optional.
                    Debug.Print fldLoop.Value
            End Select
        Next fldLoop

        Debug.Print "Property values in rstEmployees"
        ' Enumerate the Properties collection of the
        ' Recordset object.
        For Each prpLoop In .Properties
            On Error Resume Next
            ' Because Value is the default property of a
            ' Property object, the use of the actual keyword
            ' here is optional.
            If prpLoop <> "" Then Debug.Print "    " & _
                prpLoop.Name & " = " & prpLoop.Value
            On Error GoTo 0
        Next prpLoop

        .Close
    End With

    dbsNorthwind.Close

End Sub