Connecting Tech Pros Worldwide Help | Site Map

Parameters and Append Queries

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 12th, 2005, 09:56 PM
Bob Darlington
Guest
 
Posts: n/a
Default Parameters and Append Queries

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, 09:56 PM
Galina
Guest
 
Posts: n/a
Default 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]
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.