Solved

handling dates in vba access 2007

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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Suggested Solutions

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now