ACC2000: Using Eval Function with Parameters in Parameter Queries

ID: Q198462


The information in this article applies to:
  • Microsoft Access 2000


SUMMARY

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

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, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals 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 needs. If you have limited programming experience, you may want to contact a Microsoft Certified Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:

http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp


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:


  3. 
       Query: QryEval
       ----------------------------------------
       Type: Select Query
    
       Field: OrderID
          Table: Orders
       Field: OrderDate
          Table: Orders
          Criteria: =Eval("Forms!FrmEval!Text0") 
  4. Save the QryEval query and close it.


  5. Create the following new form not based on any table or query in Design view:


  6.    
       Form: FrmEval
       -----------------------------
       Caption: Eval Form
    
       Text box:
          Name: Text0
       Command button:
          Name: Command0
          Caption: Run Query
          OnClick: [Event Procedure] 
  7. Set the OnClick property of the command button to the following event procedure.


  8. 
    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 
  9. Save the FrmEval form, and then open it in Form view.


  10. 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.



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.

Additional query words:

Keywords : kbdta QryParm
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: July 15, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.