Var, VarP Functions Example (DAO)

Microsoft Jet SQL Reference

Var, VarP Functions Example

This example uses the Orders table to estimate the variance of freight costs for orders shipped to the United Kingdom.

This example calls the EnumFields procedure, which you can find in the SELECT statement example.

Sub VarX()

    Dim dbs As Database, rst As Recordset

    ' Modify this line to include the path to Northwind

    ' on your computer.

    Set dbs = OpenDatabase("Northwind.mdb")

    ' Calculate the variance of freight costs for

    ' orders shipped to the United Kingdom.

    Set rst = dbs.OpenRecordset("SELECT " _

        & "Var(Freight) " _

        & "AS [UK Freight Variance] " _

        & "FROM Orders WHERE ShipCountry = 'UK';")

    ' Populate the Recordset.

    rst.MoveLast

    

    ' Call EnumFields to print the contents of the

    ' Recordset. Pass the Recordset object and desired

    ' field width.

    EnumFields rst, 20

    

    Debug.Print

    

    Set rst = dbs.OpenRecordset("SELECT " _

        & "VarP(Freight) " _

        & "AS [UK Freight VarianceP] " _

        & "FROM Orders WHERE ShipCountry = 'UK';")

    ' Populate the Recordset.

    rst.MoveLast

    ' Call EnumFields to print the contents of the

    ' Recordset. Pass the Recordset object and desired

    ' field width.

    EnumFields rst, 20

    dbs.Close

End Sub