By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,053 Members | 1,615 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,053 IT Pros & Developers. It's quick & easy.

Correlated sub query crashing report/not allowed sorting

P: n/a
tblProductions one to many to tblEvents

tblEvents contains StartDate

I want a report where the data are grouped by tblProductions.ProdID, and
sorted by the earliest date in each Production.

So this as a query (I've stripped out surplus fields):

SELECT qryEvent.EventName, qryProduction.ProdName, qryEvent.ProdID,
qryEvent.StartDate, qryEvent.StartTime, (SELECT First(qryEvent.StartDate)
FROM qryEvent WHERE qryEvent.ProdID = qryProduction.ProdID) AS ProdDate
FROM qryEvent INNER JOIN qryProduction ON qryEvent.ProdID =
qryProduction.ProdID
WHERE (((qryEvent.StartDate)>=Date() Or (qryEvent.StartDate) Is Null));

This gives me what I want, nearly.

1. I can't set an Order By on ProdDate, I get Syntax Error if I try.

2. Presumably related, if in a report based on this (WITHOUT an order by in
the query) I get a crash if I try to do anything useful in Sorting and
Grouping with ProdDate. Basically when I move from design to preview I get a
'this will reset break mode...' or whatever that message is. Can't see a VBA
module open or anywhere.

Any ideas why this is happening, or a better approach (not that I can really
see what's wrong with mine!)?

Cheers, Mike MacSween
Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Mike MacSween wrote:
tblProductions one to many to tblEvents

tblEvents contains StartDate

I want a report where the data are grouped by tblProductions.ProdID, and
sorted by the earliest date in each Production.

So this as a query (I've stripped out surplus fields):

SELECT qryEvent.EventName, qryProduction.ProdName, qryEvent.ProdID,
qryEvent.StartDate, qryEvent.StartTime, (SELECT First(qryEvent.StartDate)
FROM qryEvent WHERE qryEvent.ProdID = qryProduction.ProdID) AS ProdDate
FROM qryEvent INNER JOIN qryProduction ON qryEvent.ProdID =
qryProduction.ProdID
WHERE (((qryEvent.StartDate)>=Date() Or (qryEvent.StartDate) Is Null));

This gives me what I want, nearly.

1. I can't set an Order By on ProdDate, I get Syntax Error if I try.

2. Presumably related, if in a report based on this (WITHOUT an order by in
the query) I get a crash if I try to do anything useful in Sorting and
Grouping with ProdDate. Basically when I move from design to preview I get a
'this will reset break mode...' or whatever that message is. Can't see a VBA
module open or anywhere.

Any ideas why this is happening, or a better approach (not that I can really
see what's wrong with mine!)?


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
1. Don't use First() - I've never had it work as anticipated. Perhaps
you want Min() to get the first date?

2. I've found that Access (JET) queries that have a correlated subquery
in the SELECT clause do not work in reports. I've had to use Domain
Aggregate functions instead (i.e., DMin).

3. If the query is going to be used in a report don't use the ORDER BY
clause. Sort the columns using the report's Group/Sort dialog box.

If you must sort the query use the columns ordinal position instead of
the sort column's expression in the ORDER BY clause. E.g. (using your
SELECT clause, above):

ORDER BY 6

This will sort, ascending, the results by the ProdDate column: the 6th
column in the SELECT clause.

- --
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQG6JwoechKqOuFEgEQJEWACfUfEh7ZY4xGugFiaqs5A7rT XIaFAAoOwK
93MxH/jq3uNs1cnb8mdGRIeV
=Phfv
-----END PGP SIGNATURE-----

Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.