Connecting Tech Pros Worldwide Help | Site Map

Parameters and Append Queries

  #1  
Old November 12th, 2005, 10:56 PM
Bob Darlington
Guest
 
Posts: n/a
I'm trying to get the following simplified test query to work so that I can
apply it to a more complex final query.
I get a 'Too few parameters' error when I try to run the following append
query:

Dim db as DAO.Database, qd as DAO.QueryDef, prm as DAO.Parameter
Set db = Currentdb
Set qd = db.QueryDefs("aaTest")
For Each prm In qd.Parameters
prm.Value = Eval(prm.Name)
Next
db.Execute "aaTest", dbFailOnError

The SQL for aaTest is:

INSERT INTO tArrearsGrouped ( LAN, Amount)
SELECT tIncome.LAN, Sum(tIncome.AmtRec) AS SumOfAmtRec
FROM tIncome
GROUP BY tIncome.LAN
HAVING (((tIncome.LAN)=[Forms]![fTenantDetails]![LAN]));

fTenantDetails is open when the query is run, and the correct value is found
in 'For each...'.
For the final query, the parameter is buried in a right join of a query
within a query, so I cannot apply a simple 'WHERE' condition to the
db.Execute. ie the parameter needs to be applied at the level of that query.

If I convert AATest to a select query, I can open a recordset on it, so I
must be getting at least part of it right(I think).
Any ideas appreciated.

--
Bob Darlington
Brisbane


  #2  
Old November 12th, 2005, 10:56 PM
Galina
Guest
 
Posts: n/a

re: Parameters and Append Queries


Hi Bob
Neither of my parameter queries ever agreed to work taking parameter
value from a form. I have many of them and tried quite hard to use the
syntax like you do, but the only way I found is:
HAVING (((tIncome.LAN)=[Parameter Name])) in query and
prm.Value = [Forms]![fTenantDetails]![LAN] in code.
I also define parameters each on a separate line, like:
set myPar=qd![Parameter Name]
myPar=[Forms]![fTenantDetails]![LAN]
Hope it will help.
Galina

"Bob Darlington" <bob@dpcmanAX.com.au> wrote in message news:<40972011$0$12740$afc38c87@news.optusnet.com. au>...[color=blue]
> I'm trying to get the following simplified test query to work so that I can
> apply it to a more complex final query.
> I get a 'Too few parameters' error when I try to run the following append
> query:
>
> Dim db as DAO.Database, qd as DAO.QueryDef, prm as DAO.Parameter
> Set db = Currentdb
> Set qd = db.QueryDefs("aaTest")
> For Each prm In qd.Parameters
> prm.Value = Eval(prm.Name)
> Next
> db.Execute "aaTest", dbFailOnError
>
> The SQL for aaTest is:
>
> INSERT INTO tArrearsGrouped ( LAN, Amount)
> SELECT tIncome.LAN, Sum(tIncome.AmtRec) AS SumOfAmtRec
> FROM tIncome
> GROUP BY tIncome.LAN
> HAVING (((tIncome.LAN)=[Forms]![fTenantDetails]![LAN]));
>
> fTenantDetails is open when the query is run, and the correct value is found
> in 'For each...'.
> For the final query, the parameter is buried in a right join of a query
> within a query, so I cannot apply a simple 'WHERE' condition to the
> db.Execute. ie the parameter needs to be applied at the level of that query.
>
> If I convert AATest to a select query, I can open a recordset on it, so I
> must be getting at least part of it right(I think).
> Any ideas appreciated.[/color]
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
'''''''''''''The Running Update/Append Queries Using VBA code Ordeal'''''''''''''' Aaron answers 2 November 13th, 2005 02:46 AM
Parameters and Append Queries Bob Darlington answers 2 November 12th, 2005 11:47 PM
Recordset to update queries - help! Dom Boyce answers 9 November 12th, 2005 07:02 PM
Passing parameters to action stored procedures using ADO, in Access Project zlatko answers 2 July 20th, 2005 06:28 AM