Solved

handling dates in vba access 2007

Posted on 2013-02-07
3
233 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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

724 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