Okay so here's situation. I have an Access 2003 Report that builds off of a Query which pulls from a Table which is populated by a form... The data is the employee (name), the hours they worked for the day, and the project they worked. I have a Start Date and and End Date Parameter set up. I am trying to create a Weekly and a Monthly Report for cost. I need it(query maybe?) to add up all the hours worked by that employee, calculate the overtime and straight time hours, multiply those by the billing rate and then sum up the total cost for the week or month depending on the report being generated. HELP!!!! I have tried all kinds of approaches and formulas and can't get anything to work right.
You would. There's an error in there (Sorry - I'm unable to test without your database so working entirely in my head). Try this instead (The change starts at line #22) : - SELECT [subMH].[Date By Day]
-
, tE.LastName
-
, tE.FirstName
-
, tE.CraftCode
-
, tE.Classification
-
, tE.STRate
-
, tE.OTRate
-
, tE.PerDiem
-
, [subMH].[Sum Of Time]
-
, [STRate]*1.1871 AS ReimSTRate
-
, [subMH].[Sum Of Time]*[ReimSTRate]+
-
IIf([subMH].[Sum Of Time]>40,
-
([subMH].[Sum Of Time]-40)*[ReimSTRate]/2),
-
0) AS [DailyRate]
-
-
FROM Employees AS [tE] INNER JOIN
-
(
-
SELECT [Employee]
-
, Format([Date],'Short Date') AS [Date By Day]
-
, Sum([Time]) AS [Sum Of Time]
-
FROM [CEP ManHours]
-
GROUP BY [Employee]
-
, [Date]
-
) AS [subMH]
-
ON [subMH].Employee=[tE].LastName
26 9228
Could you do some VBA code in the background? - totalpay = totalhours * payrate
-
-
If (totalhours - 40) > 0 Then
-
totalpay = totalpay + ((totalhours - 40) * payrate * .5)
-
Endif
NeoPa 32,556
Expert Mod 16PB
I think you'd need to start by posting what the actual logic is of what is normal, and what overtime work.
SixDonuts has posted some code that gives you a big clue as to how you can proceed, but he was working blind as to the logic.
Welcome to Bytes! Both of you :)
Nothing is wrong with my logic!
totalhours * payrate + hours above 40 * 1/2 payrate
it's the same as
first 40 hours * payrate + hours above 40 * 3/2 payrate
NeoPa 32,556
Expert Mod 16PB
I wasn't suggesting there was anything wrong with your logic. Simply that as you have no way of knowing what the logic should be (as that is only known to the OP and not yet shared) the logic in what you posted should not be relied upon to match that in the OP's situation.
IE. Your code assumes basic hours of 40 per week and an overtime rate of 1.5 * normal rate. This is information only the OP can provide reliably. As I said though, your post indicates the sort of thing needed to handle his problem as long as you don't rely on these figures in the logic.
@NeoPa
As you stated below, straight time is 40 hours and overtime is 1.5 * any hours over straight time
NeoPa 32,556
Expert Mod 16PB
Thank you Bill. So can we assume SixDonut's code worked for you?
I'm not sure I am putting the code in the right place unfortunately... I opened up my query and then used the macro shortcut (in the Tools menu dropdown) and changed the names to reflect mine. I even tried associating it to a table and it still didn't do anything.
NeoPa 32,556
Expert Mod 16PB
Grouping can either be done in the query or the report. You would need to group by the employee and the date grouping (Week/month whatever). You also need a [Rate] field available (This apparently not, according to your first post).
In your query you'd need an extra field something like : - Sum([Hours])*[Rate]+IIf(Sum([Hours])>40,(Sum([Hours])-40)*[Rate]/2),0) AS [Due]
My Rate is ReimSTRate (Reimbursable STraight Rate) When I attempt the Sum etc. stated above I get an invalid syntax error.
NeoPa 32,556
Expert Mod 16PB
Why don't you post the SQL you actually used and I'll take a look at it for you. There is far too little info available to me otherwise.
- Option Compare Database
-
-
DailyCost = Time * (STRate * 1.1871)
-
-
If (Time - 40) > 0 Then
-
DailyCost = DailyCost + (((STRate * 1.1871) - 40) * (STRate * 1.1871) * 0.5)
-
End If
NeoPa 32,556
Expert Mod 16PB
We appear to have a problem Houston!
This is not SQL code. It is sort of VBA code, but it will never run as it is not in any procedure.
SQL code is what is within a QueryDef (saved Access query). If you open your QueryDef in design view you will have the option in the View menu to View SQL. This is where you need to be looking to effect what you need.
@NeoPa
lol... that could be a reason as to why it isn't working... I'll post it up here in a few minutes
Sorry it's been a while since I sent anything but I had to use a backup program (I totally messed up the original)... here is the SQL View. - SELECT DISTINCTROW
-
Format$([CEP ManHours].Date,'Short Date') AS [Date By Day]
-
, Employees.LastName
-
, Employees.FirstName
-
, Employees.CraftCode
-
, Employees.Classification
-
, Employees.STRate
-
, Employees.OTRate
-
, Employees.PerDiem
-
, Sum([CEP ManHours].Time) AS [Sum Of Time]
-
, [STRate]*1.1871 AS ReimSTRate
-
, ([ReimSTRate]*[Sum Of Time])+[PerDiem] AS DailyRate
-
-
FROM [CEP ManHours] INNER JOIN
-
Employees
-
ON [CEP ManHours].Employee = Employees.LastName
-
-
GROUP BY Format$([CEP ManHours].Date,'Short Date')
-
, Employees.LastName
-
, Employees.FirstName
-
, Employees.CraftCode
-
, Employees.Classification
-
, Employees.STRate
-
, Employees.OTRate
-
, Employees.PerDiem
-
, [STRate]*1.1871
-
, ([ReimSTRate]*[Sum Of Time])+[PerDiem];
NeoPa 32,556
Expert Mod 16PB
In a case like this I'd do a subquery on the [CEP ManHours] table and link that in : - SELECT [subMH].[Date By Day]
-
, tE.LastName
-
, tE.FirstName
-
, tE.CraftCode
-
, tE.Classification
-
, tE.STRate
-
, tE.OTRate
-
, tE.PerDiem
-
, [subMH].[Sum Of Time]
-
, [STRate]*1.1871 AS ReimSTRate
-
, [subMH].[Sum Of Time]*[ReimSTRate]+
-
IIf([subMH].[Sum Of Time]>40,
-
([subMH].[Sum Of Time]-40)*[ReimSTRate]/2),
-
0) AS [DailyRate]
-
-
FROM Employees AS [tE] INNER JOIN
-
(
-
SELECT [Employee]
-
, Format([Date],'Short Date') AS [Date By Day]
-
, Sum([Time]) AS [Sum Of Time]
-
FROM [CEP ManHours]
-
GROUP BY [Date]
-
) AS [subMH]
-
ON [subMH].Employee=[tE].LastName
When I tried that I received the error "You tried to execute a query that does not include the specified expression 'Employee' as part of an aggregate function."
NeoPa 32,556
Expert Mod 16PB
You would. There's an error in there (Sorry - I'm unable to test without your database so working entirely in my head). Try this instead (The change starts at line #22) : - SELECT [subMH].[Date By Day]
-
, tE.LastName
-
, tE.FirstName
-
, tE.CraftCode
-
, tE.Classification
-
, tE.STRate
-
, tE.OTRate
-
, tE.PerDiem
-
, [subMH].[Sum Of Time]
-
, [STRate]*1.1871 AS ReimSTRate
-
, [subMH].[Sum Of Time]*[ReimSTRate]+
-
IIf([subMH].[Sum Of Time]>40,
-
([subMH].[Sum Of Time]-40)*[ReimSTRate]/2),
-
0) AS [DailyRate]
-
-
FROM Employees AS [tE] INNER JOIN
-
(
-
SELECT [Employee]
-
, Format([Date],'Short Date') AS [Date By Day]
-
, Sum([Time]) AS [Sum Of Time]
-
FROM [CEP ManHours]
-
GROUP BY [Employee]
-
, [Date]
-
) AS [subMH]
-
ON [subMH].Employee=[tE].LastName
By Joe I think You've got it!!!!!!!!! I had to make a very minor repair but as you said you were doing it from your head and here I am with all my tables, the internet, AND Access 2003 For Dummies and couldn't get it!!! YOU ARE AWESOME!!!!
NeoPa 32,556
Expert Mod 16PB
Very kind of you to say so Bill :)
I'm also interested to know what minor amendments were required, if you can share that.
Hmmm.... the part I seem to be having an issue with is if there isn't overtime then it's not putting the total in the DailyTotal column... I think it has something to do with the error I keep getting about the extra ) in the expression 0) - subMH].[Sum Of Time]*[ReimSTRate]+IIf([subMH].[Sum Of Time]>40,([subMH].[Sum Of Time]-40)*[ReimSTRate]/2),0) AS DailyRate
NeoPa 32,556
Expert Mod 16PB
Why don't you post the whole SQL and the exact error message. I can't do much with a snippet of code without context I'm afraid. Too many unanswered questions.
Sorry it's been so long since I responded... I've been knee deep in 20K+ drawings/schematics... here is the code. - SELECT subMH.[Date By Day], tE.LastName, tE.FirstName, tE.CraftCode, tE.Classification, tE.STRate, tE.OTRate, tE.PerDiem, subMH.[Sum Of Time], [STRate]*1.1871 AS ReimSTRate, [subMH].[Sum Of Time]*[ReimSTRate]+IIf([subMH].[Sum Of Time]>40,([subMH].[Sum Of Time]-40)*[ReimSTRate]/2), 0) AS DailyRate
-
FROM Employees AS tE INNER JOIN [SELECT [Employee]
-
, Format([Date],'Short Date') AS [Date By Day]
-
, Sum([Time]) AS [Sum Of Time]
-
FROM [CEP ManHours]
-
GROUP BY [Employee]
-
, [Date]
-
]. AS subMH ON tE.LastName = subMH.Employee;
-
And the error is "Extra ) in query expression '0)'
NeoPa 32,556
Expert Mod 16PB
Your expression for [DailyRate (Line #1) is : - [subMH].[Sum Of Time]*[ReimSTRate]+IIf([subMH].[Sum Of Time]>40,([subMH].[Sum Of Time]-40)*[ReimSTRate]/2), 0) AS DailyRate
It should be : - [subMH].[Sum Of Time]*[ReimSTRate]+IIf([subMH].[Sum Of Time]>40,([subMH].[Sum Of Time]-40)*[ReimSTRate]/2, 0) AS DailyRate
The extra, unwarranted, closing parenthesis is after the "/2".
Another problem is waiting to bite you if you make this change on your current SQL though - See Access QueryDefs Mis-save Subquery SQL. Essentially you need to change :
to :
and :
to :
Holy Crapola if that didn't fix it all!!! I guarantee if I ever have a future problem with this stuff (which I'm sure I will) I'll be coming to byte.com... Thanks Neo!!!
NeoPa 32,556
Expert Mod 16PB Bill: Holy Crapola if that didn't fix it all!!!
I'm insulted that you should be surprised :D
J/K I'm pleased that helped. Bill: I'll be coming to byte.com... Thanks Neo!!!
If you leave the "s" off then you'll miss :D When you tell all your friends, make sure to get the link right.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Eric Whittaker |
last post by:
here's my dilemma, on the program below, i am trying to calculate overtime
pay at time and a half, but instead of only counting the hours after 40, it
counts all hrs at that rate, how can i avoid...
|
by: sg_s123 |
last post by:
============================================================================
02-Feb-04 03-Feb-04
Staff Staff 0800hr- 1300hr- 1700hr- 1900hr- 0800hr- 1300hr- 1700hr-
1900hr-
Number...
|
by: michb |
last post by:
I need to be able to calculate on a daily basis, both normal and
overtime hours for both payroll and job costing.
I also then need to calculate the above on a weekly basis, in order to
complete...
|
by: Drum2001 |
last post by:
I have designed a "Time Tracker Database"... Basically a Time Clock. I
have report that calculates the number of regular hours worked per
week.
Currently I am running the following query:...
|
by: Don G |
last post by:
Each entry in a data file includes date and time in text format - e.g.
"0601271325" = 2006, January 27th, 1:25 pm. Is there a simple way to
calculate the hours (including decimal parts) between...
|
by: deena22 |
last post by:
hello,
i'm using 'Access database' and VB 6.0. My database is named ' timesheet' and it contains a table named 'tabletimesheet'. The table contain the following fields: 'staffname, stafftype,...
|
by: iceone |
last post by:
Hi everybody,
I am monitoring a call center and i need to calculate the working hours between the moment the call is answered and the moment the call is closed.
i need to calculate the working...
|
by: Andrew G. Koptyaev |
last post by:
Is exist metod to calculate work hours for implementing project. May be some
hours per
kb ?
Somebody want to hair me to do project but I dont know how much hours I will
spend.
Thank you!
|
by: Bay0519 |
last post by:
Hi,
I need your help again... :) I'm working on access 2003. I have a query that calculate overtime daily using:
IIf(<=8,0,-8)
but how can I add saturday and sunday in this criteria? if...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |