Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: Using Eval Function with Parameters in Parameter Queries


View products that this article applies to.

This article was previously published under Q198462
Moderate: Requires basic macro, coding, and interoperability skills.

↑ Back to the top


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.

↑ Back to the top


More information

The following example demonstrates how to use the Eval() function with a parameter expression in a query:
  1. Open the sample database Northwind.mdb.
  2. 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")
    					
  3. Save the QryEval query and close it.
  4. 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]
    					
  5. 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
    					
  6. Save the FrmEval form, and then open it in Form view.
  7. 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.
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:
  1. Open the QryEval query in Design view.
  2. Change the OrderDate criteria to [Forms]![FrmEval]![Text0].
  3. Save the query and close it.
  4. Open the FrmEval form in Form view.
  5. 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.

↑ Back to the top


References

For more information about parameter queries, click Microsoft Access Help on the Help menu, type "parameter queries" in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

↑ Back to the top


Keywords: KB198462, kbprogramming, kbhowto

↑ Back to the top

Article Info
Article ID : 198462
Revision : 4
Created on : 10/11/2006
Published on : 10/11/2006
Exists online : False
Views : 335