Running Parameter Queries : SQL Parameter « Access « VBA / Excel / Access / Word






Running Parameter Queries

 
Sub RunParameterQuery(datStart As Date, datEnd As Date)
    Dim cmd As ADODB.Command
    Dim rst As ADODB.Recordset

    Set cmd = New ADODB.Command
    cmd.ActiveConnection = CurrentProject.Connection
    cmd.CommandText = "Select * from Employees " & _
        "Where BirthDate Between ? and ?"
    cmd.CommandType = adCmdText

    Set rst = cmd.Execute(Parameters:=Array(datStart, datEnd))

    Do Until rst.EOF
        Debug.Print rst("EmployeeID"), rst("BirthDate")
        rst.MoveNext
    Loop
    rst.Close
    Set rst = Nothing
    Set cmd = Nothing

End Sub

 








Related examples in the same category

1.Creat a SQL statement and append parameter as ceriteria
2.Creating a Parameter Query
3.Build the SQL statement dynamically
4.Executing a SQL Statement Containing Parameters
5.User InputBox to read SQL statement parameter