ACC: "Too few parameters" Using AddAllToList() FunctionID: Q141620
|
Advanced: Requires expert coding, interoperability, and multiuser skills.
When you try to open a parameter query from code, as is done in the
AddAllToList() function provided in the Developer Solutions sample
application (Solutions.mdb), you may receive the following error message:
Too few parameters. Expected 1.
The combo box or list box's RowSource property is set to an SQL statement or query object name that is a parameter query. The parameter query may be used to limit the selection of items in the list based on a selection in a different list or control on the form. When opening a recordset on a query in Visual Basic, which the AddAllToList() function attempts to do, the parameters must be filled in explicitly.
Modify the AddAllToList() function to explicitly fill in the parameters for
the recordset being used.
The steps to reproduce the behavior are provided below using the
SelectProduct combo box on the EditProducts form in the Developer Solutions
sample application. Further information is provided demonstrating how you
can work around this behavior by creating a copy of the AddAllToList()
function and modifying it to explicitly fill the parameters to the
LimitProductList query used to populate the SelectProduct combo box.
Too few parameters. Expected 1.
Find What: AddAllToList
Replace With: FillSelectProduct
Search: Current Procedure
' Open the recordset defined in the RowSource property.
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset(ctl.RowSource, dbOpenSnapshot)
to read:
' Open the recordset defined in the RowSource property.
Set dbs = CurrentDb()
Dim qdf As QueryDef
Set qdf = dbs.QueryDefs(ctl.RowSource)
qdf.Parameters("Forms!EditProducts!SelectCategory") = _
Forms!EditProducts!SelectCategory
Set rst = qdf.OpenRecordset(dbOpenSnapshot)
NOTE: If your RowSource property uses an SQL statement instead of a
saved query object, you can replace the line above that reads
Set qdf = dbs.QueryDefs(ctl.RowSource)
to read:
Set qdf = dbs.CreateQueryDef("", ctl.RowSource)
For more information about parameters, search for "parameter queries" using the Microsoft Access 97 Help Index.
Keywords : kberrmsg DcmSltn
Version : 7.0 97
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: April 27, 1999