I'm new to acess and working on my first db. I haven't started using code yet so i still working with wizards. I am using Acess 2000 on an Windows XP.
My problem is i have a time field that i need too run a query on and the sum needs to be in hundreds of hours but i've tried everything and as soon as the sum gets to 23:59 it starts over at 0:00. I need this to show large hours numbers
19 3204
oooooooooookkkk kkkkkkkkkkkk
MMcCarthy 14,534
Recognized Expert Moderator MVP
I'm new to acess and working on my first db. I haven't started using code yet so i still working with wizards. I am using Acess 2000 on an Windows XP.
My problem is i have a time field that i need too run a query on and the sum needs to be in hundreds of hours but i've tried everything and as soon as the sum gets to 23:59 it starts over at 0:00. I need this to show large hours numbers
Try this: -
-
SELECT Field1, Field2,
-
CInt(Sum([TimeField])) * 24 + Hour(Sum([TimeField]) As TotalHours,
-
Minute(Sum([TimeField])) As Mins
-
FROM Tablename
-
GROUP BY Field1, Field2;
-
-
NeoPa 32,564
Recognized Expert Moderator MVP
Or a slightly modified version : - SELECT Field1, Field2,
-
Int(Sum([TimeField])) * 24 + Hour(Sum([TimeField]) As TotalHours,
-
Minute(Sum([TimeField])) As Mins
-
FROM Tablename
-
GROUP BY Field1, Field2
Not just for fun - CInt rounds as it goes. Int() truncates, as is required here.
MMcCarthy 14,534
Recognized Expert Moderator MVP
Or a slightly modified version : - SELECT Field1, Field2,
-
Int(Sum([TimeField])) * 24 + Hour(Sum([TimeField]) As TotalHours,
-
Minute(Sum([TimeField])) As Mins
-
FROM Tablename
-
GROUP BY Field1, Field2
Not just for fun - CInt rounds as it goes. Int() truncates, as is required here.
Believe it or not, I originally had it as an Int but changed my approach a couple of times and ended up with CInt. I never remember the rules anyway. Have to go look them up on a regular basis. My mind is like a sieve.
Mary
Thanks Neopa and mmccarthy
I’m still having trouble with this one. I never used code before so be patient. After this database is finished this week I’ll learn more about code.
I have a table called [PTP Vehical daily log] (don’t mind the misspelling)
I have three fields in it [start time], [end time], and [night time].
I need to subtract the [start time] from the [end time] then add the [night time] to this total.
Finally I need a grand total in hours that will not roll over at 23:59 like it does.
I tried to follow your example but I keep getting a ‘snytax error (missing operative)’.Wha t I came up with is below.
I would appreciate any help you can give and I promise if I can get this working I wont bother you anymore!!!!!!!! !!!
SELECT
CInt(Sum(([PTP Vehical daily log]![end time]-[PTP Vehical daily log]![start time])+[PTP Vehical daily log]![night time]) * 24 + Hour(Sum(([PTP Vehical daily log]![end time]-[PTP Vehical daily log]![start time])+[PTP Vehical daily log]![night time])) AS TotalHours, Minute(Sum(([PTP Vehical daily log]![end time]-[PTP Vehical daily log]![start time])+[PTP Vehical daily log]![night time])) AS Mins
FROM [PTP Vehical daily log]
GROUP BY [PTP Vehical daily log].[start time], [PTP Vehical daily log].[end time], [PTP Vehical daily log].[night time]
MMcCarthy 14,534
Recognized Expert Moderator MVP
OK try this, the group by is only needed if you want your results broken out over something like EmployeeID. I think the main problem was a misplaced bracket. -
-
SELECT (Int(Sum(([end time] - [start time]) + [night time])) * 24
-
+ Hour(Sum(([end time] - [start time]) + [night time])) AS TotalHours,
-
Minute(Sum(([end time] - [start time]) + [night time])) AS Mins
-
FROM [PTP Vehical daily log];
MMcCarthy 14,534
Recognized Expert Moderator MVP
It Worked
Thanks
No Problem
NeoPa 32,564
Recognized Expert Moderator MVP - SELECT Sum([end time] - [start time] + [night time]) AS TotTime, _
-
Int(TotTime) * 24 + Hour([TotTime]) AS TotalHours, _
-
Minute([TotTime]) AS Mins
-
FROM [PTP Vehical daily log];
Bear in mind, unless you want this across the whole recordset, you'll need a GROUP BY clause.
This is fundamentally the same as Mary's code.
The advantage is the complicated field is worked out just the once (in the code - Mary's would also be worked out once at execution) and then reused more ligibly. It also introduces a useful concept available in SQL.
I hope this makes sense.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Martin Lacoste |
last post by:
Ok, before I headbutt the computer... don't know why when I add
criteria in a query, I get an 'invalid procedure call'. I also don't
know why after searching the help in access, the various access
newsgroups, the access support centre, I can seem to find no similar
situation.
I am not using any references, or VBA at all in the first place....
|
by: Brian |
last post by:
Hello,
Basically, I'm running a query on a form's activation, and I'd like to
have the results of the query be placed into other fields on the same
form automatically.
Does anybody know how this can be done?
I've tried setting the default value of the text fields on the form to
be equal to ! using Access' expression
|
by: Maxi |
last post by:
There is a lotto system which picks 21 numbers every day out of 80
numbers.
I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21)
Here is the structure and sample data:
"Date","P1","P2","P3","P4","P5","P6","P7","P8","P9","P10","P11","P12","P13","P14","P15","P16","P17","P18","P19","P20","P21"...
|
by: rivka.howley |
last post by:
I wrote some code that creates a table with a date/time field at
15-minute intervals. Here's how I create and populate the table
With tblDataTemp
..Fields.Append .CreateField("CT_ID", dbLong)
..Fields.Append .CreateField(strTmpIDFld, dbLong)
..Fields.Append .CreateField(strTmpDateFld, dbDate)
..Fields.Append .CreateField(strTmpDataFld,...
|
by: Macroman |
last post by:
MS Access XP, running on Win XP, Processor 2.4Ghz , 512Mb RAM, 40Gb Hard
drive
Table 1 has 167,000 records and contains the following fields
tblone_custID
tblone_easting
tblone_northing
Table 2 has 423,000 records and contains the following fields
tbltwo_custID
| |
by: commodityintelligence |
last post by:
Greetings,
I am merging a series of different tables into one query to export decision-making information. I have some architecture issues I need to ask for help on. I have no programming training.
I will explain my structure before asking my questions.
I have data from a table (updated monthly by adding the most current month’s data)...
|
by: Doris |
last post by:
It does not look like my message is posting....if this is a 2nd or 3rd
message, please forgive me as I really don't know how this site works.
I want to apologize ahead of time for being a novice with MS Access
and VBA. I desperately need help with 2 queries that I am trying to
put together. I want to thank anyone that can help me out with...
|
by: DeanL |
last post by:
Hi all,
I'm trying to set up a query that runs from a command button on a form
(simple enough so far), what I want the query to do is take values
from the fields on the form (seven fields in total) but sometimes not
all the fields will be filled. If a field is empty then the
assumption is that no filter will be applied to that field in the...
|
by: Richard Hollenbeck |
last post by:
I am very sorry about the (almost) re-post, but you will see that my first
question wasn't very clear; I have another question I posted this morning
called, "in DAO: Run time error 3061 Too few parameters...."
I have read many articles on the web about how to make a dynamic report
based on a cross-tab query. But for some reason mine never...
|
by: Sinner |
last post by:
Hi,
I have a field name 'USER' in tableMAIN.
How do I replace the user names with corresponding user names. I can
do that in xl using vlookup but now I'm trying to find a way to do
that in access.
For a user mismatch, it should give NA
Thx.
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |