WHERE Clause Example (DAO)

Microsoft Jet SQL Reference

WHERE Clause Example

The following example assumes the existence of a hypothetical Salary field in an Employees table. Note that this field does not actually exist in the Northwind database Employees table.

This example selects the LastName and FirstName fields of each record in which the last name is King.

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

Sub WhereX()

    Dim dbs As Database, rst As Recordset

    ' Modify this line to include the path to Northwind

    ' on your computer.

    Set dbs = OpenDatabase("Northwind.mdb")

    ' Select records from the Employees table where the

    ' last name is King.

    Set rst = dbs.OpenRecordset("SELECT LastName, " _

        & "FirstName FROM Employees " _

        & "WHERE LastName = 'King';")

    

    ' Populate the Recordset.

    rst.MoveLast

    

    ' Call EnumFields to print the contents of the

    ' Recordset.

    EnumFields rst, 12

    dbs.Close

End Sub