Parameters

Although you can't add parameters to a QueryDef using DAO, you can retrieve information about them using the following construct:

db.QueryDefs("myQuery").parameters(0).Name

For example, you can retrieve the date the QueryDef was created, the date it was last updated, its SQL statement (so you can change it in code), a flag indicating whether the query is updatable, and so on.

You can also specify a query parameter's value in order to specify the value of criteria to filter the query's output, or the selected records on which the query operates. For example, the following procedure sets a reference to an existing query called myActionQuery, sets the value of its parameter (Organisation), and then executes the query.

Public Sub ExecParameterQuery() Dim dbs As Database Dim qdf As DAO.QueryDef

Set dbs = CurrentDb

Set qdf = dbs.QueryDefs("myActionQuery")

'Set the value of the QueryDef's parameter qdf.Parameters("Organisation").Value = "Microsoft"

'Execute the query qdf.Execute dbFailOnError

'Clean up qdf.Close Set qdf = Nothing Set dbs = Nothing End Sub

Was this article helpful?

0 0

Post a comment