?
Solved

handling dates in vba access 2007

Posted on 2013-02-07
3
Medium Priority
?
234 Views
Last Modified: 2013-02-07
when my users travel, I need to record the time it takes from departure to arrival.
I have all the code to handle this if my users depart and arrive on the same day.  I run into an issue when they depart one day and arrive the following.

if user a departs 10/20/2012 at 23:05 and arrives 10/21/2012 at 11:10 their elapsed time is 12 hours (rounded to nearest quarter hour).  when I try to run this through my code i get a negative result and the program crashes.  How do I handle this type of event?
0
Comment
Question by:sptech
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 22

Accepted Solution

by:
Kelvin Sparks earned 2000 total points
ID: 38863194
You need to calculate the difference between the two in the smallest denominator that your using (minutes I suspect) - probably using the datediff function and then convert to hours.


Kelvin
0
 

Author Closing Comment

by:sptech
ID: 38863324
that is what I suspected and that is what I coded.  It works.  Nice to have an expert reaffirm my newbie thoughts.
0
 
LVL 85
ID: 38863349
In addition to Kelvin's suggestion:

Here's info on DateDiff:

http://office.microsoft.com/en-us/access-help/datediff-function-HA001228811.aspx

And here's a good resource with lots of examples:

http://office.microsoft.com/en-us/access-help/calculate-the-difference-between-two-date-or-time-values-HP001098486.aspx

Essentially you'd do something like this:

DateDiff ("n", YourFirstDate, YourLastDate)

That would give the number of Minutes between the two. Obviously you could divide by 60 to get hours.

When supplying the dates be sure they're formed correctly. Access expects them to be in a form like:

01/01/2012 12:30:00

Would represent 30 minutes after Noon on Jan 1 of 2012.

01/01/2010 00:30:00

Would represent 30 minutes after Midnight on Jan 1 of 2012

Access will generally accept most formats, but the more explicit you are with your Dates, the more reliable these functions will be.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question