>
qdfNewHires.Parameters(0) = 5
Dim dbsCurrent As Database Dim qdfParam As QueryDef, prmEnum As Parameter Dim rstParam As Recordset Dim X As Integer Set dbsCurrent = DBEngine.Workspaces(0).OpenDatabase("Northwind.mdb") Set qdfParam = dbsCurrent.QueryDefs("ParamQuery") ' Open existing ' QueryDef. qdfParam.Parameters("Order Date") = "10/11/94" ' Set parameters. qdfParam.Parameters("Ship Date") = "11/4/94" Set rstParam = qdfParam.OpenRecordset() ' Open Recordset. For X = 0 To qdfParam.Parameters.Count - 1 Set prmEnum = qdfParam.Parameters(X) Debug.Print prmEnum.Name ' Print parameter properties. Debug.Print prmEnum.Type Debug.Print prmEnum.Value Next X rstParam.CloseExample (Microsoft Access) The following example creates a new parameter query and supplies values for the parameters.
Sub NewParameterQuery() Dim dbs As Database, qdf As QueryDef, rst As Recordset Dim prm As Parameter, strSQL As String ' Return Database object pointing to current database. Set dbs = CurrentDb ' Construct SQL string. strSQL = "PARAMETERS [Beginning OrderDate] DateTime, " & _ "[Ending OrderDate] DateTime; SELECT * FROM Orders " & _ "WHERE ([OrderDate] Between[Beginning OrderDate] " & _ "And [Ending OrderDate]);" ' Create new QueryDef object. Set qdf = dbs.CreateQueryDef("ParameterQuery", strSQL) ' Supply values for parameters. qdf.Parameters![Beginning OrderDate] = #4-1-95# qdf.Parameters![Ending OrderDate] = #4-30-95# End Sub