Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Invalid bracketing problem

Status
Not open for further replies.

NeilT123

Technical User
Jan 6, 2005
302
GB
Yesterday I imported all of my data into a new database and now the following union query won't run. I get a message saying invalid bracketing of name Select[Field code

I understand from elsewhere on this forum that Access sometimes "rebrackets" queries but can anyone help with the correction.

Thank you in advance for any replies
Code:
SELECT [FieldCode], Sum(Effect) AS SumOfEffect, Yr
FROM [SELECT [FieldCode],NYr0 as Effect,CInt([OM Application Year]) As Yr FROM qry2rptA1
UNION ALL SELECT [FieldCode],NYr1,CInt([OM Application Year]+1) FROM qry2rptA1
UNION ALL SELECT [FieldCode],Nyr2,CInt([OM Application Year]+2) FROM qry2rptA1
]. AS U
GROUP BY [FieldCode], Yr;
 
I have managed to fix this. In case it is of any use to anyone else here is what I did.
Changed the [ before the SELECT in line 2 to (
Changed the ] in line 5 to ) and deleted the dot

This sorted out the problem but I notice that having run the query Access has changed the code to
Code:
SELECT [FieldCode], Sum(Effect) AS SumOfEffect, Yr
FROM [SELECT [FieldCode],NYr0 as Effect,CInt([OM Application Year]) As Yr FROM qry2rptA1
UNION ALL SELECT [FieldCode],NYr1,CInt([OM Application Year]+1) FROM qry2rptA1
UNION ALL SELECT [FieldCode],Nyr2,CInt([OM Application Year]+2) FROM qry2rptA1
]. AS U
GROUP BY [FieldCode], Yr;
which is exactly as above!!!!!
 
NeilT123

That makes us two! I face the same in a similar union query.
I hope some1 can explain why...
 
This is a known bug.
A work around is to create the union query named, say, qryU2rptA1:
SELECT [FieldCode],NYr0 as Effect,CInt([OM Application Year]) As Yr FROM qry2rptA1
UNION ALL SELECT [FieldCode],NYr1,CInt([OM Application Year]+1) FROM qry2rptA1
UNION ALL SELECT [FieldCode],Nyr2,CInt([OM Application Year]+2) FROM qry2rptA1

And now your query:
SELECT [FieldCode], Sum(Effect) AS SumOfEffect, Yr
FROM qryU2rptA1
GROUP BY [FieldCode], Yr

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top