Solved

handling dates in vba access 2007

Posted on 2013-02-07
3
232 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 84
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
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

739 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