Build the three queries as stored queries. Use the third query as the record
source for the report.
If you have the form open, you can refer to the values in its controls.
SELECT [Name]
, Store
, Sum(AmountSpent) as TotalAmount
FROM SomeTable
WHERE [Date] Between [Forms]![Your Form Name]![Your Control Name] and
[Forms]![Your Form Name]![Your Other Control Name]
GROUP BY [Name], Store
By the way, I assume that Name and Date are NOT your real field names. If they
are you should be aware that they are reserved words in Access and MUST be
surrounded by brackets OR fully named with the table name preceding the field
name - [SomeTable].[Date]
Hi John,
Thanks again for your time! I do know about referencing an opened form's
controls' values and the reserved words. This is just a completely
simplified version of what I have in real life.
Several points I'm confused about though:
Your originally suggested Query One has the [Store] field in it, which
shouldn't be there since I don't have [Store] in my Query 1. My Query 1 &
Query 2 are related by [Name] and [Date]. I didn't bring it up last time
since I thought I could just modify your suggested queries as follows (T-SQL
syntax):
Query One:
SELECT EmpName, SUM(Amount) AS TotalAmount
FROM dbo.Amounts
WHERE (DateStamp BETWEEN @BDate AND @EDate)
GROUP BY EmpName
Query Two:
SELECT EmpName, Store, SUM(Qty) AS TotalQty
FROM dbo.Stores
WHERE (DateStamp BETWEEN @BDate AND @EDate)
GROUP BY EmpName, Store
Query Three:
SELECT A.[Name], B.Store, TotalAmount, TotalQTY
FROM [Query One] as A INNER JOIN [Query Two] as B
On A.[Name] = B.[Name]
I understand that conceptually those 3 queries work perfectly. But in my
ADP file, after creating 2 "functions" called Query 1 and Query 2 (which work
fine the way they're supposed to) and trying to join them together, the
following SQL statement is created automatically:
SELECT [Query 1].EmpName, [Query 1].TotalAmount, [Query 2].Store,
[Query 2].TotalQty FROM dbo.[Query 1](,) [Query 1] INNER JOIN dbo.[Query
2](,) [Query 2] ON [Query 1].EmpName = [Query 2].EmpName
That SQL statement gets back with an "Incorrect syntax" critical error that
I have no clue how to fix. I assume it's because it's trying to join 2
parameter functions????
The next question is I'm not quite understanding where you want me to put
that last SQL statement (in your last post)??? VB code in the Open_Report
event?
Thanks so much again!
-ngan
==================
> Build the three queries as stored queries. Use the third query as the record
> source for the report.
[quoted text clipped - 92 lines]
> > > >
> > > > Thanks much!
John Spencer - 02 May 2006 20:14 GMT
I am stuck myself. I think that with T-SQL you would have to do something
else than what I am suggesting. I was using Access SQL with JET backend.
You might be able to do something like the following. My T-SQL is rusty and
this may or may not work.
SELECT A.[Name], B.Store, TotalAmount, TotalQTY
FROM
(SELECT EmpName, SUM(Amount) AS TotalAmount
FROM dbo.Amounts
WHERE (DateStamp BETWEEN @BDate AND @EDate)) as A
INNER JOIN
(SELECT EmpName, Store, SUM(Qty) AS TotalQty
FROM dbo.Stores
WHERE (DateStamp BETWEEN @BDate AND @EDate)
GROUP BY EmpName, Store) as B
ON A.[Name] = B.[Name]
If this fails, perhaps you should start a new thread - be sure to emphasize
you are doing this with T-SQL and in an ADP.
> Hi John,
> Thanks again for your time! I do know about referencing an opened form's
[quoted text clipped - 160 lines]
>> > > >
>> > > > Thanks much!