Question : Crosstab with subquery

Hi.

I'm trying to generate a crosstab from a query which itself uses a subquery and getting the error"Microsoft Jet database engine does not recognize 'tblMonths.fmonth' as a valid field name or expression'.

The solutions I've found involve setting fmonth as a paramter to the crosstab, but this just results in a box being thrown up prompting me for a value of fmonth when I try to run the query which is not what I want.

My base query is called qryGenerateTimeSeries_Top1
SELECT tblData.Group, tblMonths.fMonth, tblData.VR, (SELECT TOP 1 tblTransfers.To
FROM tblTransfers
WHERE (((tblTransfers.TxDate)lMonths.fmonth) AND ((tblTransfers.Group)=tblData.Group))
ORDER BY tblTransfers.Group, tblTransfers.TxIdx;) AS ActingDMC
FROM tblData, tblMonths
ORDER BY tblData.Group, tblMonths.fMonth;

and the crosstab that throws the error is

TRANSFORM Sum(qryGenerateTimeSeries_Top1.VR) AS SumOfVR
SELECT qryGenerateTimeSeries_Top1.ActingDMC
FROM qryGenerateTimeSeries_Top1
GROUP BY qryGenerateTimeSeries_Top1.ActingDMC
PIVOT qryGenerateTimeSeries_Top1.fMonth;

The query qryGenerateTimeSeries_Top1 runs fine and gives me the results I am expecting.
What am i doing wrong?

Answer : Crosstab with subquery

You should rather ask what is Access doing wrong... I think Jet engine does not have enough power to process this complex task.

You have two options (at least):
1) Create temporary table from your query and calculate pivot results from this table:

SELECT tblData.Group, tblMonths.fMonth, tblData.VR, (SELECT TOP 1 tblTransfers.To
FROM tblTransfers
WHERE (((tblTransfers.TxDate)Months.fmonth) AND ((tblTransfers.Group)=tblData.Group))
ORDER BY tblTransfers.Group, tblTransfers.TxIdx) AS ActingDMC
INTO YourTempTable
FROM tblData, tblMonths
ORDER BY tblData.Group, tblMonths.fMonth;

2) Try newer Access version which does not use Jet engine but much better ACE engine
Random Solutions  
 
programming4us programming4us