B
Bob B.
I am trying to set up a querydef to allow me to pull the top 5 worst scrap
producers from a table based on user entered starting and ending dates and an
upper and lower range for total pounds produced. Once the query is created, I
will use additional code to pull the top 5 products from a recordset of the
query results.
The querydef appears to work fine as the query is created and the data is
flawless. However, when I try to issue the Set rst = qdf.OpenRecordset(), I
get the following error:
Run-time error ‘3061’:
Too few parameters. Expected 4.
I do this in other applications I have created and there is no issue. I
have even copied the code from them and replaced it with the specifics for
this application only to yield the same results.
Below is my exact code. Any help that can be provided as to what I am
doing wrong and that may help me correct this issue would be greatly
appreciated. Thank you in advance for your help.
Dim db As Database
Dim qdf As QueryDef
Dim rst As Recordset
Set db = CurrentDb()
'Build a query called ScrapNumbers and select the all fields from
Physical Property Data.
'Order the list by ScrapRate and attach that query to the Currrent
Database.
Set qdf = db.CreateQueryDef("ScrapNumbers", "SELECT [PHYSICAL PROPERTY
DATA].[PRODUCT NAME], [PHYSICAL PROPERTY DATA].[LOT NUMBER], [PHYSICAL
PROPERTY DATA].[DATE PRODUCED], [PHYSICAL PROPERTY DATA].CUSTOMER, [PHYSICAL
PROPERTY DATA].[POUNDS PROD], [PHYSICAL PROPERTY DATA].[RM LBS USED],
[PHYSICAL PROPERTY DATA].EXTRUDER_NUMBER, [POUNDS PROD]/[RM LBS USED] AS
ScrapRate FROM [PHYSICAL PROPERTY DATA]WHERE ((([PHYSICAL PROPERTY
DATA].[DATE PRODUCED]) Is Not Null And ([PHYSICAL PROPERTY DATA].[DATE
PRODUCED]) Between [Forms]![frmTopScrapProducersReport]![fldStartingDate] And
[Forms]![frmTopScrapProducersReport]![fldEndingDate]) AND (([PHYSICAL
PROPERTY DATA].[POUNDS PROD])>[Forms]![frmTopScrapProducersReport]![fldFrom]
And ([PHYSICAL PROPERTY DATA].[POUNDS
PROD])<[Forms]![frmTopScrapProducersReport]![fldTo]) AND (([PHYSICAL PROPERTY
DATA].[RM LBS USED])<>0))ORDER BY [POUNDS PROD]/[RM LBS USED] DESC;")
Set rst = qdf.OpenRecordset()
rst.Close
db.QueryDefs.Delete qdf.Name
db.Close
producers from a table based on user entered starting and ending dates and an
upper and lower range for total pounds produced. Once the query is created, I
will use additional code to pull the top 5 products from a recordset of the
query results.
The querydef appears to work fine as the query is created and the data is
flawless. However, when I try to issue the Set rst = qdf.OpenRecordset(), I
get the following error:
Run-time error ‘3061’:
Too few parameters. Expected 4.
I do this in other applications I have created and there is no issue. I
have even copied the code from them and replaced it with the specifics for
this application only to yield the same results.
Below is my exact code. Any help that can be provided as to what I am
doing wrong and that may help me correct this issue would be greatly
appreciated. Thank you in advance for your help.
Dim db As Database
Dim qdf As QueryDef
Dim rst As Recordset
Set db = CurrentDb()
'Build a query called ScrapNumbers and select the all fields from
Physical Property Data.
'Order the list by ScrapRate and attach that query to the Currrent
Database.
Set qdf = db.CreateQueryDef("ScrapNumbers", "SELECT [PHYSICAL PROPERTY
DATA].[PRODUCT NAME], [PHYSICAL PROPERTY DATA].[LOT NUMBER], [PHYSICAL
PROPERTY DATA].[DATE PRODUCED], [PHYSICAL PROPERTY DATA].CUSTOMER, [PHYSICAL
PROPERTY DATA].[POUNDS PROD], [PHYSICAL PROPERTY DATA].[RM LBS USED],
[PHYSICAL PROPERTY DATA].EXTRUDER_NUMBER, [POUNDS PROD]/[RM LBS USED] AS
ScrapRate FROM [PHYSICAL PROPERTY DATA]WHERE ((([PHYSICAL PROPERTY
DATA].[DATE PRODUCED]) Is Not Null And ([PHYSICAL PROPERTY DATA].[DATE
PRODUCED]) Between [Forms]![frmTopScrapProducersReport]![fldStartingDate] And
[Forms]![frmTopScrapProducersReport]![fldEndingDate]) AND (([PHYSICAL
PROPERTY DATA].[POUNDS PROD])>[Forms]![frmTopScrapProducersReport]![fldFrom]
And ([PHYSICAL PROPERTY DATA].[POUNDS
PROD])<[Forms]![frmTopScrapProducersReport]![fldTo]) AND (([PHYSICAL PROPERTY
DATA].[RM LBS USED])<>0))ORDER BY [POUNDS PROD]/[RM LBS USED] DESC;")
Set rst = qdf.OpenRecordset()
rst.Close
db.QueryDefs.Delete qdf.Name
db.Close