Hi There,
I am trying to execute a query using openRecordset on a query called 'AccountValues'. The 'AccountValues' query relies on another query, 'Prices', which in turn relies on a form for two parameters.
The information flow is:
2 parameters -> Prices -> AccountBalances -> {my query}
Ideally, I would be able to perform the following: - strSQL = "SELECT Account, SubAccount, Sector, Symbol, Sum(MarketValueStart) AS SumOfMarketValueStart, Sum(MarketValueEnd) AS SumOfMarketValueEnd FROM AccountValues GROUP BY Account, SubAccount, Sector, Symbol;"
-
Set CustData = qdf.OpenRecordset(strSQL)
However, when I run this I get the following error message:
"Too few parameters. Expected 2."
I understand that this is because the 'Prices' query requires these parameters. Now, I have been able to open 'AccountValues' with the correct parameters using the following code. - Dim CustDB As dataBase, CustData, CustTotals As Recordset
-
Dim qdf As QueryDef, prm As Parameter
-
-
Set CustDB = DBEngine.Workspaces(0).Databases(0)
-
Set qdf = CustDB.QueryDefs("AccountValues")
-
-
For Each prm In qdf.Parameters
-
prm.value = Eval(prm.Name)
-
Next prm
-
-
Set CustData = qdf.OpenRecordset(dbOpenDynaset)
However, this is only opens the 'AccountValues' query with the correct parameters, not the QUERY ON AccountValues.
Does anyone know how I might be able to go one step further and execute a query on the AccountValues query?
Thanks in advance for your help.
5 5710
Hi There,
I am trying to execute a query using openRecordset on a query called 'AccountValues'. The 'AccountValues' query relies on another query, 'Prices', which in turn relies on a form for two parameters.
The information flow is:
2 parameters -> Prices -> AccountBalances -> {my query}
Ideally, I would be able to perform the following: - strSQL = "SELECT Account, SubAccount, Sector, Symbol, Sum(MarketValueStart) AS SumOfMarketValueStart, Sum(MarketValueEnd) AS SumOfMarketValueEnd FROM AccountValues GROUP BY Account, SubAccount, Sector, Symbol;"
-
Set CustData = qdf.OpenRecordset(strSQL)
However, when I run this I get the following error message:
"Too few parameters. Expected 2."
I understand that this is because the 'Prices' query requires these parameters. Now, I have been able to open 'AccountValues' with the correct parameters using the following code. - Dim CustDB As dataBase, CustData, CustTotals As Recordset
-
Dim qdf As QueryDef, prm As Parameter
-
-
Set CustDB = DBEngine.Workspaces(0).Databases(0)
-
Set qdf = CustDB.QueryDefs("AccountValues")
-
-
For Each prm In qdf.Parameters
-
prm.value = Eval(prm.Name)
-
Next prm
-
-
Set CustData = qdf.OpenRecordset(dbOpenDynaset)
However, this is only opens the 'AccountValues' query with the correct parameters, not the QUERY ON AccountValues.
Does anyone know how I might be able to go one step further and execute a query on the AccountValues query?
Thanks in advance for your help.
How about applying a Filter to your Recordset based on a Parameterized Query? - Dim MyDB As DAO.Database, MyRS As DAO.Recordset, qdf As DAO.QueryDef
-
-
Set MyDB = CurrentDb()
-
Set qdf = MyDB.QueryDefs("qryEmployee")
-
-
'Evaluate Parameters
-
For Each prm In qdf.Parameters
-
prm.Value = Eval(prm.Name)
-
Next prm
-
-
'Open Recordset on Paramter Query
-
Set MyRS = qdf.OpenRecordset(dbOpenDynaset)
-
MyRS.MoveLast: MyRS.MoveFirst
-
MsgBox "Recordset Count before Filtering = " & MyRS.RecordCount
-
-
'Let's apply a Filter to the Original Recordset
-
MyRS.Filter = "[Platoon]='A'"
-
-
'Create a New 'Filtered' Recordset based on the Original
-
Dim rstFiltered As DAO.Recordset
-
Set rstFiltered = MyRS.OpenRecordset()
-
rstFiltered.MoveLast: rstFiltered.MoveFirst
-
MsgBox "Recordset Count after Filtering = " & rstFiltered.RecordCount
-
-
MyRS.Close
-
rstFiltered.Close
Just a couple of things to remember when Filtering a Recordset:- The new Filtering doesn't take effect until you create a new Recordset based on the old one.
- The Filter property doesn't apply to Table-Type Recordsets.
- The new Filtering will never retrieve additional Rows from the original Source Tables. It will Filter only Rows that are in the base Recordset you are filtering.
NOTE: Let me know how you make out.
- strSQL = "SELECT Account, SubAccount, Sector, Symbol, Sum(MarketValueStart) AS SumOfMarketValueStart, Sum(MarketValueEnd) AS SumOfMarketValueEnd FROM AccountValues GROUP BY Account, SubAccount, Sector, Symbol"
-
Set CustData = qdf.OpenRecordset(strSQL)
you don't need the semicoln
ADezii,
Thanks for your suggestion. It's not so much that I need to filter the initial recordset, but rather group and sum the data (as per the Select statement at the top of the post).
Any ideas how I could achieve that?
My best suggestion is to create your query in Access, under the queries tab. Once you get the query you want working, then look at the query in sql view and copy and paste that into your recordset. This should help you trouble shoot it better. Sorry I can't help you more but I would need to see the results displayed to understand where the syntax is wrong. But like I said create your sql view under quieres in access and when you get it to display how you like copy it to your recordset.
good luck
This is the query I would like to execute: - SELECT Account, SubAccount, Sector, Symbol, Sum(MarketValueStart) AS SumOfMarketValueStart, Sum(MarketValueEnd) AS SumOfMarketValueEnd
-
FROM AccountValues
-
GROUP BY Account, SubAccount, Sector, Symbol;
However, AccountValues is a query that takes inputs from a form. I cannot, therefore, open a recordSet with the above query without being asked to enter parameters.
I can, however, open a recordSet of 'AccountValues' using CustDB.QueryDefs("AccountValues"), but this will not allow me to GROUP the data, which is the whole point of me trying to do this.
It is not a question of how to write an SQL select statement. I know exactly which statement to use. I just don't know how to use the above statement AND feed in the correct parameters using VBA.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Robert Mark Bram |
last post by:
Hi All!
My ASP page below receives the following error:
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E10)
Too few parameters. Expected 2.
/polyprint/test.asp, line 31
...
|
by: Nuno |
last post by:
Is there any SQL Error?
Or I have to use Select case in VB code to control SQL instead.
Thank you for any ans.
Nuno
|
by: John |
last post by:
(acc2002)
I have a command button (cmdView) on a form (frmOverview)that needs to
open a form (frmFilmProjectAgreements) and its two subforms (control
names: fsubAgreements and fsubPayments)...
|
by: Max Harvey |
last post by:
Hi,
I have looked at the example called "Open Parameter queries from code"
from the site http://www.mvps.org/access/queries/qry0003.htm
I made up a test which I though looked pretty close...
|
by: Ryan Hubbard |
last post by:
Is it possible to get the recordset from an open query window? So you
run the query. The window is open. Can vba retrieve this data?
|
by: lauren quantrell |
last post by:
When I open an Access form I can have no recordset specified, then in
the form's OnOpen event I can do something like:
Me.paramaters = "@SomeColumn = 22)"
Me.recordsource = "dbo.sproc123"
But I...
|
by: allyn44 |
last post by:
Hello,
I have built a serch form for users to edit records. I only want them
to pull up the record they need, and I want to check for nulls. There
should not be dupes becasue the underlying...
|
by: fniles |
last post by:
I am using VB.NET 2003, SQL 2000, and SqlDataReader.
As I read data from tblA, I want to populate tblB. I use SQLDataReader for
both tables. I do not use thread.
When I ExecuteReader on tblB, I...
|
by: wallconor |
last post by:
Hi,
I am having a problem using Dreamweaver CS3 standard recordset paging behavior. It doesn’t seem to work when I pass parameter values from a FORM on my search page, to the recordset on my...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |