473,396 Members | 2,018 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How do I calculate overnight hours in Microsoft access?

I am trying to make sure that users cannot enter more downtime than there is available up-time. My calculation works just fine for day shifts but all of my graveyard people are showing negative hours. I have one date field and then a [StartTime] and an [EndTime]. Here is the formula that is working for my day shift users.

If ([EndTime] - [StartTime]) - [PlannedDwnTime] < [DowntimeTotal] Then
Cancel = True
MsgBox "Your available time cannot be less than your downtime."
End If
Aug 11 '16 #1
5 2263
jforbes
1,107 Expert 1GB
You might try something like this:
Expand|Select|Wrap|Line Numbers
  1. If [EndTime] < [StartTime] Then
  2.    If (([EndTime] + 24) - [StartTime]) - [PlannedDwnTime] < [DowntimeTotal] Then Cancel = True
  3. Else
  4.    If ([EndTime]  - [StartTime]) - [PlannedDwnTime] < [DowntimeTotal] Then Cancel = True
  5. End IF
  6. If Cancel Then MsgBox "Your available time cannot be less than your downtime."
The idea is if the EndTime is less than the Start Time, then that means the shift went over Midnight. So, add 24 hours to the EndTime and perform the check like normal. There's other ways to accomplish this, but I think this will give you the basic idea.
Aug 11 '16 #2
I haven't had any luck with that yet but it has gotten me thinking about other options. What about having two calculated fields depending on whether the user is night shift or day shift? Or maybe having the user enter time as a number instead of a time. (6am would be 600) but that would probably require too much training... Still working on this problem. Not having any luck with internet searches either.
Aug 12 '16 #3
jforbes
1,107 Expert 1GB
OK, lets take a step backwards.

Where is the code that you have provided located?
What is the DataType of fields?
  • [EndTime]
  • [StartTime]
  • [PlannedDwnTime]
  • [DowntimeTotal]


What kind of experience would you like your users to have? And what data are you attempting to capture?

You could have them enter the Time and Date for the StartTime and EndTime, which could be somewhat complicated, or you could have them just enter a Numeric Time if you don't need to store off the Date. Or do you need only one Date, Shift Start and then the amount of time worked? You could provide your users with a ComboBox with times in 15 minute increments and have them select the closest time.

What kind of Calculations or Filtering are you planning on performing on this data you capture? What do you want to show up on your reports. Are you going to need to know the specific Dates for Start and End, or are you just going to need to know the amount of hours per shift?


An old friend used to call this Begin with End in Mind. Knowing what you want to end up with helps you figure out what you need to cover at the start.
Aug 15 '16 #4
@jforbes My data types are "Date/Time" for the date as well as for the times ([StartTime] and [EndTime]). [PlannedDwnTime] and [DowntimeTotal] are both "Number" fields. I need them to enter the exact times because of other calculations. I am having them enter one date (the date they start) and then the times in separate boxes. I still haven't had luck with getting the correct minutes of [UpTime]. Thank you for your help Jforbes.
Aug 18 '16 #5
@jforbes I did it! Here is my calculation. It is working for both day shift and night shift. `=(((IIf([EndTime]<[StartTime],[EndTime]-[StartTime]+1,[EndTime]-[StartTime]))*24)*60)`
Aug 18 '16 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

27
by: Chuck Grimsby | last post by:
(Repost, due to lack of submissions...) The Microsoft Access Product Group (the people who build Microsoft Access) want your help! One of the main things we're working on for the near future...
8
by: Larry__Weiss | last post by:
What kind of licensing is needed to be able to use the Microsoft Access product and distribute the applications? In other words, what version of Microsoft Access does a developer need to buy in...
7
by: tpers | last post by:
How can I convert a datetime value (i.e. now()) to Greenwich Mean Time(GMT) in Microsoft Access 2003? I have an Access database that is shared by a few people across different time zones. The...
17
by: Pam Ammond | last post by:
I need to use Microsoft Access Automation within a Visual Studio 2003 program written in C# for Windows Forms. When a button is clicked in my VS.NET program, I want it to run a Microsoft Access...
4
by: bbdobuddy | last post by:
Hi, How do I open a Microsoft Access 2003 form from Visual Basic.net Thanks in advance bbdobuddy
5
by: somersbar | last post by:
hello all, im trying to connect to a microsoft access database from an ASP.NET web form. i keep getting the following error though: ERROR Could not use '(unknown)'; file already in use....
0
by: bazzer | last post by:
hey, i am using visual basic.net 2003 and have an ASP.NET webform application thats accessing a microsoft access 2003 database. i kept getting the following error when i tried to run it: ERROR ...
0
by: bazzer | last post by:
hey, im trying to access a microsoft access database from an ASP.NET web application in visual basic 2003.NET. i get the following error when i try running it: Server Error in...
0
by: sofiashaharom | last post by:
I've connected my program (developed in VB 2008) to a microsoft access (2003) database.One of the columns stored in the database is the Start_Date. The purpose of my program is to calculate the...
2
by: hemal8888 | last post by:
Hello All, i want to need Idea about how to calculate break hours from in/out details In My Database Design is: ID EmpEntryDate EmpInTime EmpOutTime Empid 1 2014-09-22 10:28 ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
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,...
0
jinu1996
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.