Home  |  About  |   Search   

What's New
Table Of Contents
Credits
Netiquette
10 Commandments 
Bugs
Tables
Queries
Forms
Reports
Modules
APIs
Strings
Date/Time
General
Downloads
Resources
Search
Feedback
mvps.org

RunCommand Constants

Terms of Use


 

Queries: Open Parameter queries from code

Author(s)
Dev Ashish

(Q) How do I open a Parameter Query from code?

(A) In order to open parametric queries, you need to explicitly pass each parameter by using the Parameters property before opening a recordset based on the query.

For example, in the following code snippet, the Query "Qry1" has two parameters; namely, [Please enter Code:] and [Please enter city:].

'************ Code Start ****************
Dim db As Database 'current database
Dim rs As Recordset 'holds query resultset
Dim qdfParmQry As QueryDef 'the actual query object
    Set db = CurrentDb()
    Set qdfParmQry = db.QueryDefs("Qry1")
    qdfParmQry("Please Enter Code:") = 3

    ' or try this alternate method
    ' to pass the parameter
   
    qdfParmQry![Please Enter City:] = "New York"
    Set rs = qdfParmQry.OpenRecordset()
'************** Code End ***************

1998-2009, Dev Ashish & Arvin Meyer, All rights reserved. Optimized for Microsoft Internet Explorer