Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

handling dates in vba access 2007

Posted on 2013-02-07
3
Medium Priority
?
235 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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.

636 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