ACC: "Too few parameters. Expected 1" Error MessageID: Q105522
|
Advanced: 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.
Too few parameters. Expected 1
# parameters were expected, but only 0 were supplied.
You 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).
This behavior is by design.
This 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.
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]
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]
Dim MyDB As Database, MyQDef As QueryDef
Set MyDB = CurrentDb()
Set MyQDef = MyDB.QueryDefs("Parameter Query")
MyQDef![Please enter date:] = #8/8/94#
Dim MyDB As Database
Dim MyQDef As QueryDef
Set MyDB = CurrentDB()
Set MyQDef = MyDB.OpenQueryDef("Parameter Query")
MyQDef![Please enter date:] = "#12/12/93#"
Query: Customer Orders Parameter Query
-----------------------------------------------------------------
Type: Select Query
Field: CustomerID (or Customer ID in Microsoft Access 1.x or 2.0)
Table: Orders
Criteria: [Forms]![Search Form]![Customer To Find]
Field: OrderID (or Order ID in Microsoft Access 1.x or 2.0)
Table: Orders
Field: OrderDate (or Order Date in Microsoft Access 1.x or 2.0)
Table: Orders
Form: Search Form
--------------------------------
Text box:
ControlName: Customer To Find
ControlSource: CustomerID
Command button:
ControlName: Button0
Caption: ParamQD
OnClick: =ParamQD()
'****************************************************************
' Declarations Section
'****************************************************************
Option Compare Database
Option Explicit
'****************************************************************
' Function ParamQD()
'
' Purpose: To demonstrate how to set the value of a parameter that
' references a form.
'****************************************************************
Function ParamQD()
Dim MyDB As Database
Dim MyQDef As QueryDef
Dim MyDyna As Recordset '(in Microsoft Access 7.0 and 97 only)
'Dim MyDyna As Dynaset '(in Microsoft Access 1.x and 2.0 only)
Set MyDB = CurrentDB()
Set MyQDef = MyDB.QueryDefs("Customer Orders Parameter Query")
'(above line in Microsoft Access 7.0 and 97 only)
'Set MyQDef = MyDB.OpenQueryDef("Customer Orders Parameter_
' Query")
'(above line in Microsoft Access 1.x and 2.0 only)
' Set the value of the parameter.
MyQDef![Forms!Search Form!Customer To Find] = Forms![Search _
Form]![Customer To Find]
' Create the recordset (or dynaset).
Set MyDyna = MyQDef.OpenRecordset() '(in Microsoft Access 7.0 and
' 97 only)
' Set MyDyna = MyQDef.CreateDynaset()'(in Microsoft Access 1.x
' and 2.0 only)
MyDyna.MoveLast
MsgBox MyDyna.RecordCount
MyDyna.Close
MyQDef.Close
End Function
For 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
Keywords : kberrmsg kbprg PgmObj QryParm
Version : 1.0 1.1 2.0 7.0 97
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: March 27, 1999