Error 3061: Too few Parameters. Expected 1

ryetee

Registered User.
Local time
Today, 13:16
Joined
Jul 30, 2013
Messages
952
I have 2 queries. The first returns multiple rows for each record I want to report on. The second query is more or less the same but without the multiple rows. In the second query I concatenate the data I want from the multiple rows into 1 field in the second query. This works. If I hard code some criteria into the first query this again works. If I try and pick up the criteria for the first query from a form then this query returns the correct data but if I try and run the second query I get the error in the subject.

The SCL for the pair that work are
SELECT StockLocation.StockLocationDescription, StockLocation.StockLocation, [Component Parts].[Component Part ID] AS CPID, [Component Parts].[Component Part No], StockLocation_1.StockLocation AS StockLoc, StockLocation.StockLocation AS SL
FROM StockLocation INNER JOIN ((([Component Parts] INNER JOIN PartsStockLocation ON [Component Parts].[Component Part ID] = PartsStockLocation.CPartsID) INNER JOIN PartsStockLocation AS PartsStockLocation_1 ON [Component Parts].[Component Part ID] = PartsStockLocation_1.CPartsID) INNER JOIN StockLocation AS StockLocation_1 ON PartsStockLocation_1.StockLocationID = StockLocation_1.ID) ON StockLocation.ID = PartsStockLocation.StockLocationID
WHERE (((StockLocation.StockLocation)="R1"));


SELECT StockLocation.StockLocation, [Component Parts].[Component Part No], [Component Parts].[Quantity in Stock], ConcatRelated("[StockLoc]","[QuantityInStock]","[CPID] = " & [Component Parts].[Component Part id]) AS OtherLocation
FROM StockLocation INNER JOIN ([Component Parts] INNER JOIN PartsStockLocation ON [Component Parts].[Component Part ID] = PartsStockLocation.CPartsID) ON StockLocation.ID = PartsStockLocation.StockLocationID;

The pair that do not work (and only the where should be different) are

SELECT StockLocation.StockLocationDescription, StockLocation.StockLocation, [Component Parts].[Component Part ID] AS CPID, [Component Parts].[Component Part No], StockLocation_1.StockLocation AS StockLoc, StockLocation.StockLocation AS SL
FROM StockLocation INNER JOIN ((([Component Parts] INNER JOIN PartsStockLocation ON [Component Parts].[Component Part ID] = PartsStockLocation.CPartsID) INNER JOIN PartsStockLocation AS PartsStockLocation_1 ON [Component Parts].[Component Part ID] = PartsStockLocation_1.CPartsID) INNER JOIN StockLocation AS StockLocation_1 ON PartsStockLocation_1.StockLocationID = StockLocation_1.ID) ON StockLocation.ID = PartsStockLocation.StockLocationID
WHERE (((StockLocation.StockLocation)=[forms]![Dates for stock reports]![txtStockLoc]));

SELECT StockLocation.StockLocation, [Component Parts].[Component Part No], [Component Parts].[Quantity in Stock], ConcatRelated("[StockLoc]","[QuantityInStock]","[CPID] = " & [Component Parts].[Component Part id]) AS OtherLocation
FROM StockLocation INNER JOIN ([Component Parts] INNER JOIN PartsStockLocation ON [Component Parts].[Component Part ID] = PartsStockLocation.CPartsID) ON StockLocation.ID = PartsStockLocation.StockLocationID;
 
The recordset in ConcatRelated can't resolve the form reference. One workaround that can work:

WHERE StockLocation.StockLocation=Eval('[forms]![Dates for stock reports]![txtStockLoc]')
 
The recordset in ConcatRelated can't resolve the form reference. One workaround that can work:

WHERE StockLocation.StockLocation=Eval('[forms]![Dates for stock reports]![txtStockLoc]')


You sir are a star.
Thanks!
 
Happy to help!


I spoke to soon!!
The parameters are obtained from a form.
If I fill details on the form then
1. The query works
2. If I then open the report this works also.

BUT
3. If I run the report from the aforementioned form itself (click on button and effectively run DoCmd.OpenReport "QuantityInstockAtLocation", acViewPreview, , strWhere, , strArgs then I get the first page no problem at all - all concatenated fields as expected but if I then navigate to next page for each line on that following page I get error 2450.

Are you familiar with the concatenate function.
Appears tobe falling over on line

Set rs = DBEngine(0)(0).OpenRecordset(strSQl, dbOpenDynaset)

Also if I then try and create a PDF suing the ribbon I get the 2450 error for all records on all pages
 
Does your code close the form after opening the report? It needs to be open while the report is.
 
Does your code close the form after opening the report? It needs to be open while the report is.

Yes it does!
Brilliant! What's the next level above a superstar?
 
Happy to help! I don't know, I'll let you know if I ever get there. I think I'm at "strong intermediate" level.
 

Users who are viewing this thread

Back
Top Bottom