Microsoft KB Archive/198462

= ACC2000: Using Eval Function with Parameters in Parameter Queries =

Article ID: 198462

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q198462



Moderate: Requires basic macro, coding, and interoperability skills.



SUMMARY
If you use the Eval function with a parameter expression in the criteria of a query, you do not need to explicitly declare the parameter in order to run the query in code.

If you do not use the Eval function and you do not explicitly declare the parameter, you may receive the following error message when you run the query in code, where n represents the number of parameters:

Run-time error 3061:

Too few parameters. Expected n.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.



MORE INFORMATION
The following example demonstrates how to use the Eval function with a parameter expression in a query:  Open the sample database Northwind.mdb.  Create the following new query based on the Orders table:   Query: QryEval Type: Select Query

Field: OrderID Table: Orders Field: OrderDate Table: Orders Criteria: =Eval("Forms!FrmEval!Text0")  Save the QryEval query and close it.  Create the following new form not based on any table or query in Design view:  Form: FrmEval -  Caption: Eval Form

Text box: Name: Text0 Command button: Name: Command0 Caption: Run Query OnClick: [Event Procedure]   Set the OnClick property of the command button to the following event procedure. Private Sub Command0_Click Dim MyDB As Database Dim MySet As RecordSet Set MyDB = CurrentDb Set MySet = MyDB.OpenRecordSet("QryEval") MySet.MoveFirst MsgBox MySet!OrderID MySet.Close End Sub </li> Save the FrmEval form, and then open it in Form view.</li> Type 8/4/94 in the text box, and then click the Run Query button. Note that a message box appears that displays an Order ID number.</li></ol>

If you want to further test what happens when you do not use the Eval function and you do not explicitly declare the query parameter, follow these steps: <ol> Open the QryEval query in Design view.</li> Change the OrderDate criteria to [Forms]![FrmEval]![Text0].</li> Save the query and close it.</li> Open the FrmEval form in Form view.</li> Type 8/4/94 in the text box, and then click the Run Query button.

Note that you receive the following error message:

Run-time error 3061:

Too few parameters. Expected 1.

</li></ol>

<div class="references_section">