ACC: "Too few parameters. Expected 1" Error MessageLast reviewed: July 11, 1997Article ID: Q105522 |
The information in this article applies to:
SYMPTOMSAdvanced: Requires expert coding, interoperability, and multiuser skills. When you run a parameter query in Visual Basic (or Access Basic), you may receive one of the following error messages.
In Microsoft Access 7.0 and 97
Too few parameters. Expected 1 In Microsoft Access 1.x and 2.0
# parameters were expected, but only 0 were supplied.This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual. NOTE: Visual Basic for Applications is called Access Basic in Microsoft Access versions 1.x and 2.0. For more information about Access Basic, please refer to the "Introduction to Programming" manual in Microsoft Access version 1.x or the "Building Applications" manual in Microsoft Access version 2.0.
CAUSEYou receive one of these error messages if you do not set the values of all the parameters in the parameter query in Visual Basic (or Access Basic).
STATUSThis behavior is by design.
MORE INFORMATIONThis section contains an example of the syntax you use to set the values of a parameter, the sample code to create a query to set the values of a parameter, and the sample code to create a function to set the values of a parameter in parameter queries. NOTE: You have to explicitly assign the parameter in DAO; you do not have to explicitly assign the parameter with the DoCmd.OpenQuery (or DoCmdOpenQuery in Microsoft Access 1.x and 2.0). The reason for this is that DAO uses low-level operations that give you more flexibility (that is, you can assign a variable to a parameter rather than a forms reference) but you have to do the housekeeping that Microsoft Access does behind the scenes with DoCmd actions. On the other hand, the DoCmd actions operate at a higher level than DAO. When executing a DoCmd action, Microsoft Access makes some assumptions about what to do with parameters--you don't have any flexibility in making them accept a different value.
Syntax to Set the Value of a ParameterTo set the value of a parameter that references a form, use the following syntax.
In Microsoft Access 7.0 and 97
Dim MyDB As Database Dim MyQDef As QueryDef Set MyDB = CurrentDB() Set MyQDef = MyDB.QueryDefs("Parameter Query") MyQDef![Forms!Form Name!ControlName] = Forms![Form Name]![ControlName] In Microsoft Access 1.x and 2.0NOTE: In the following sample code, an underscore (_) is used as a line-continuation character. Remove the underscore from the end of the line when re-creating this code.
Dim MyDB As Database Dim MyQDef As QueryDef Set MyDB = CurrentDB() Set MyQDef = MyDB.OpenQueryDef("Parameter Query") MyQDef![Forms!Form Name!ControlName] = Forms![Form _ Name]![ControlName]In the examples, the definition variable, the exclamation point, and the parameter, which is enclosed in brackets, are to the left of the equal sign. Note that if the form name or control name in a form reference contains spaces, it is usually enclosed in brackets. Do not include the brackets if you are setting the value of the form reference parameter. However, do include the brackets if you are referencing the form listed to the right of the equal sign.
Code to Create a Query to Set the Value of a ParameterTo create a query that prompts you to enter the date when you run the query, create a module and enter the following code:
In Microsoft Access 7.0 and 97
Dim MyDB As Database, MyQDef As QueryDef Set MyDB = CurrentDb() Set MyQDef = MyDB.QueryDefs("Parameter Query") MyQDef![Please enter date:] = #8/8/94# In Microsoft Access 1.x and 2.0
Dim MyDB As Database Dim MyQDef As QueryDef Set MyDB = CurrentDB() Set MyQDef = MyDB.OpenQueryDef("Parameter Query") MyQDef![Please enter date:] = "#12/12/93#"NOTE: If you have more than one parameter in the query, add a line similar to the last line in the code for each parameter.
Sample Function to Set the Value of a ParameterThe following example uses the Orders table from the sample database Northwind.mdb (or NWIND.MDB in Microsoft Access 1.x or 2.0). To create a function that sets the value of a parameter in a parameter query, follow these steps:
REFERENCESFor more information about setting the values of a parameter, search the Help Index for "parameter queries, creating" and then view the available topics.
|
Additional query words: expected supplied
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |