Like Operator Example (DAO)

Microsoft Jet SQL Reference

Like Operator Example

This example returns a list of employees whose names begin with the letters A through D.

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

Sub LikeX()

    Dim dbs As Database, rst As Recordset

    ' Modify this line to include the path to Northwind

    ' on your computer.

    Set dbs = OpenDatabase("Northwind.mdb")

    ' Return a list of employees whose names begin with

    ' the letters A through D.

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

        & " FirstName FROM Employees" _

        & " WHERE LastName Like '[A-D]*';")

    ' Populate the Recordset.

    rst.MoveLast

    ' Call EnumFields to print the contents of the

    ' Recordset. Pass the Recordset object and desired

    ' field width.

    EnumFields rst, 15

    

    dbs.Close

End Sub