Jane-
Can you copy and paste a sample of the output? Particularly some rows that show what you don't expect. Note that it should return a value only for the row that has the highest VehicleCostID within a given date.
John Viescas, Author
Effective SQL
SQL Queries for Mere Mortals
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications
(Paris, France)
On Jul 8, 2016, at 5:49 PM, jcross@crossproducts.plus.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:
Thanks John
It's nearly working. Some dates work great, but others stay blank. Probably to do with US/UK formatting, but I can't work it out yet.
I've tried breaking it down in a query, so that I'm just trying to get it to return the DMax VehicleCostID for each date, but some dates return nothing?
DMax("VehicleCostID","tblVehicleCosts","[CostDate]=#" & format([CostDate],"dd-mmm-yyyy") & "#")
Best regards
Jane
---In MS_Access_Professionals@yahoogroups.com, <JohnV@...> wrote :
---In MS_Access_Professionals@yahoogroups.com, <JohnV@...> wrote :
Jane-
---In MS_Access_Professionals@yahoogroups.com, <JohnV@...> wrote :
You could try an expression like:
Daily: IIf(IsNull(DLookup("VehicleCostID", "tblVehicleCosts", "CostDate = #" & [CostDate] & "# AND VehicleCostID > " & [VehicleCostID], DSum("Price * Qty", "tblVehicleCosts", "CostDate = #" & [CostDate] & "#"), Null)
What this is doing: If there is no other record with the same CostDate and an ID greater than the current record (in other words, this is the last record for the date), then return the Sum of Price times Qty for all records with the same CostDate. If not the last record, then return a "blank". This should still execute a DLookup for each row, but it will do the Sum only when on the last row for a given date.
John Viescas, Author
Effective SQL
SQL Queries for Mere Mortals
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications
(Paris, France)
On Jul 5, 2016, at 3:44 PM, jcross@... [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:
Hi John
Yes each record has a unique VehicleCostID -autonum PK.
tblVehicleCosts
VehicleCostID - autonum PK
VehicleIDFK long
CostDate date
PartDesc Text
Price Currency
Qty Double
Units Text
NettTotal Currency
Thanks John
---In MS_Access_Professionals@yahoogroups.com, <JohnV@...> wrote :
Jane-
What is the layout of the table? Is there possibly an AutoNumber primary key? If so, I might be able to come up with something.
John Viescas, Author
Effective SQL
SQL Queries for Mere Mortals
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications
(Paris, France)
On Jul 5, 2016, at 12:47 PM, jcross@... [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:
__._,_.___
Posted by: John Viescas <johnv@msn.com>
Reply via web post | • | Reply to sender | • | Reply to group | • | Start a New Topic | • | Messages in this topic (6) |
Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.
.
__,_._,___
Tidak ada komentar:
Posting Komentar