Avatar of schmir1
schmir1Flag for United States of America

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_Unit]*[Quantity]","[OrdersTotal_Subquery]","[Project_Num] = Forms![BOM_Queries]![cboProjects]  "),"$#.00")
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]));

Open in new window

SQL

Avatar of undefined
Last Comment
puppydogbuddy
Avatar of puppydogbuddy
puppydogbuddy

try this:
GrandTotal: Format(DSum("[Price_Per_Unit]*[Quantity]","[OrdersTotal_Subquery]","[Project_Num] = " & Forms![BOM_Queries]![cboProjects]),"$#.00")
Avatar of schmir1
schmir1
Flag of United States of America image

ASKER

Sorry, no luck. I get a can't find name error on this part:
"[Project_Num] = " & Forms![BOM_Queries]![cboProjects]
Avatar of puppydogbuddy
puppydogbuddy

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].[cboProjects]
___________________________________________________
"Orders.[Project_Num] = " & Forms![BOM_Queries].[cboProjects].Column(0)
Avatar of puppydogbuddy
puppydogbuddy

I should have used the bang operator (!) instead of dot operator (.) in above expressions
Avatar of schmir1
schmir1
Flag of United States of America image

ASKER

No luck with either of those.  I'm wondering if the Format or DSum functions still work in Access 2007.
Avatar of puppydogbuddy
puppydogbuddy

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
Avatar of schmir1
schmir1
Flag of United States of America image

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.
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]));

Open in new window

Avatar of puppydogbuddy
puppydogbuddy

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)=CStr([Forms]![BOM_Queries]![cboProjects].Value)));

see this link:   http://msdn.microsoft.com/en-us/library/aa337293(SQL.90).aspx 
Avatar of puppydogbuddy
puppydogbuddy

p.s.
If cboProjects is numeric, remove the CStr function.
Avatar of schmir1
schmir1
Flag of United States of America image

ASKER

I tried your suggestion above but get the same error.
ASKER CERTIFIED SOLUTION
Avatar of puppydogbuddy
puppydogbuddy

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of schmir1
schmir1
Flag of United States of America image

ASKER

I tried that and everything else I could think of.  Nothing works.
Avatar of schmir1
schmir1
Flag of United States of America image

ASKER

I hope you don't mind but I'm going to up this up to the SQL Syntax people.
Avatar of puppydogbuddy
puppydogbuddy

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.
Avatar of schmir1
schmir1
Flag of United States of America image

ASKER

Thanks for getting me in the right direction. It was the double quotes around [Price_Per_Unit]*[Quantity]
Avatar of puppydogbuddy
puppydogbuddy

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  
SQL
SQL

SQL (Structured Query Language) is designed to be used in conjunction with relational database products as of a means of working with sets of data. SQL consists of data definition, data manipulation, and procedural elements. Its scope includes data insert, query, update and delete, schema creation and modification, and data access control.

61K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo