schmir1
asked on
Query OK in Access 2000 and not in Access 2007
In the code section below is a query that works in Access 2000 but not in Access 2007. The following part (from line 1 of code section) is where the error is:
GrandTotal: Format(DSum("[Price_Per_Un it]*[Quant ity]","[Or dersTotal_ Subquery]" ,"[Project _Num] = Forms![BOM_Queries]![cboPr ojects] "),"$#.00")
GrandTotal: Format(DSum("[Price_Per_Un
SELECT Orders.Project_Num, Orders_Subtable.Component_Num, Orders_Subtable.Quantity, Orders_Subtable.Price_Per_Unit, Sum([Price_Per_Unit]*[Quantity]) AS Total, Format(DSum("[Price_Per_Unit]*[Quantity]","[OrdersTotal_Subquery]","[Project_Num] = Forms![BOM_Queries]![cboProjects] "),"$#.00") AS GrandTotal
FROM Orders INNER JOIN Orders_Subtable ON Orders.Orders_ID = Orders_Subtable.Orders_ID
GROUP BY Orders.Project_Num, Orders_Subtable.Component_Num, Orders_Subtable.Quantity, Orders_Subtable.Price_Per_Unit, Format(DSum("[Price_Per_Unit]*[Quantity]","[OrdersTotal_Subquery]","[Project_Num] = Forms![BOM_Queries]![cboProjects] "),"$#.00")
HAVING (((Orders.Project_Num)=[Forms]![BOM_Queries]![cboProjects]));
ASKER
Sorry, no luck. I get a can't find name error on this part:
"[Project_Num] = " & Forms![BOM_Queries]![cboPr ojects]
"[Project_Num] = " & Forms![BOM_Queries]![cboPr
try each of the syntax variations below:
Allen Browne documents that there are expressions in prior access versions that are not understood by Access 2007. See compatibility issues. http://allenbrowne.com/Access2007.html#Bugs
I am assuming that cboProjects returns numeric and that Project_Num is the bound column of combo box
"Orders.[Project_Num] = " & Forms![BOM_Queries].[cboPr ojects]
__________________________ __________ __________ _____
"Orders.[Project_Num] = " & Forms![BOM_Queries].[cboPr ojects].Co lumn(0)
Allen Browne documents that there are expressions in prior access versions that are not understood by Access 2007. See compatibility issues. http://allenbrowne.com/Access2007.html#Bugs
I am assuming that cboProjects returns numeric and that Project_Num is the bound column of combo box
"Orders.[Project_Num] = " & Forms![BOM_Queries].[cboPr
__________________________
"Orders.[Project_Num] = " & Forms![BOM_Queries].[cboPr
I should have used the bang operator (!) instead of dot operator (.) in above expressions
ASKER
No luck with either of those. I'm wondering if the Format or DSum functions still work in Access 2007.
Bob,
can you post the code as you entered them, so I can double check. Also, provide details as to what you mean by didn't work....error message? wrong result? DSum and Format still work in 2007.
Thanks
can you post the code as you entered them, so I can double check. Also, provide details as to what you mean by didn't work....error message? wrong result? DSum and Format still work in 2007.
Thanks
ASKER
Also, my database back-end was Access 2000 and now it is SQL Server 2005. Here is the error message:
The expression you entered as a query parameter produced this error: 'DTLDB *Access2007 to SQL Server 2005* Development from Rev. 3.7 to Rev. 3.8 3/12/09 can't find the name 'CR60075' you
entered in the expression'
Below is the entire query.
The expression you entered as a query parameter produced this error: 'DTLDB *Access2007 to SQL Server 2005* Development from Rev. 3.7 to Rev. 3.8 3/12/09 can't find the name 'CR60075' you
entered in the expression'
Below is the entire query.
SELECT Orders.Project_Num, Orders_Subtable.Component_Num, Orders_Subtable.Quantity, Orders_Subtable.Price_Per_Unit, Sum([Price_Per_Unit]*[Quantity]) AS Total, Format(DSum("[Price_Per_Unit]*[Quantity]","[OrdersTotal_Subquery]","Orders![Project_Num] = " & [Forms]![BOM_Queries]![cboProjects]),"$#.00") AS GrandTotal
FROM Orders INNER JOIN Orders_Subtable ON Orders.Orders_ID = Orders_Subtable.Orders_ID
GROUP BY Orders.Project_Num, Orders_Subtable.Component_Num, Orders_Subtable.Quantity, Orders_Subtable.Price_Per_Unit, Format(DSum("[Price_Per_Unit]*[Quantity]","[OrdersTotal_Subquery]","Orders![Project_Num] = " & [Forms]![BOM_Queries]![cboProjects]),"$#.00")
HAVING (((Orders.Project_Num)=[Forms]![BOM_Queries]![cboProjects]));
Rob,
I don't believe it is Access 2007 that is giving you the problem....I believe the problem is that SQL Server requires parameters to be presented differently in order to process it (pass-thru query??). I am not real familiar with sql server syntax, but I gave it a try. Change the last line of your query to the following.
(((Orders.Project_Num)=CSt r([Forms]! [BOM_Queri es]![cboPr ojects].Va lue)));
see this link: http://msdn.microsoft.com/en-us/library/aa337293(SQL.90).aspx
I don't believe it is Access 2007 that is giving you the problem....I believe the problem is that SQL Server requires parameters to be presented differently in order to process it (pass-thru query??). I am not real familiar with sql server syntax, but I gave it a try. Change the last line of your query to the following.
(((Orders.Project_Num)=CSt
see this link: http://msdn.microsoft.com/en-us/library/aa337293(SQL.90).aspx
p.s.
If cboProjects is numeric, remove the CStr function.
If cboProjects is numeric, remove the CStr function.
ASKER
I tried your suggestion above but get the same error.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
I tried that and everything else I could think of. Nothing works.
ASKER
I hope you don't mind but I'm going to up this up to the SQL Syntax people.
Don't mind at all. It does not make sense that you can't get it to work even if you replace parameter with a hard value.
ASKER
Thanks for getting me in the right direction. It was the double quotes around [Price_Per_Unit]*[Quantity ]
Bob,
wow!! that explains things. So, the parameter problem was a symptom,not a cause......it was the cryptic messages that had you fixated on the parameter as the causing The query, as posted, could not have run in Access 2000 because of the quotation marks, either. Glad I was able to help you resolve this. Thanks for the points and grade.
pDog
wow!! that explains things. So, the parameter problem was a symptom,not a cause......it was the cryptic messages that had you fixated on the parameter as the causing The query, as posted, could not have run in Access 2000 because of the quotation marks, either. Glad I was able to help you resolve this. Thanks for the points and grade.
pDog
GrandTotal: Format(DSum("[Price_Per_Un