Calculate End Time

G

Guest

I am trying to add 210 minutes to whatever start time inputed. I have:
PacerStartTime format property as Short Time and default as 8:30

I tried
Private Sub PacerStartTime_Exit(Cancel As Integer)
Me.PacerEndTime = Me.PacerStartTime + 210
End Sub

I receive the error "The value you entered isn't valid for this field."
What am I missing?
 
G

Guest

I found initial problem to resolve the error, but it is not adding 210
minutes. It places 7/28/1900 8:30:00 AM in PacerEndTime
 
F

fredg

I am trying to add 210 minutes to whatever start time inputed. I have:
PacerStartTime format property as Short Time and default as 8:30

I tried
Private Sub PacerStartTime_Exit(Cancel As Integer)
Me.PacerEndTime = Me.PacerStartTime + 210
End Sub

I receive the error "The value you entered isn't valid for this field."
What am I missing?

Assuming [PacerStartTime] is a valid Date datatype field, then

Me.[PacerEndTime] = DateAdd("n",210,[PacerStartTime])

As long as your table is storing [PacerStartTime], there would be no
need to store this computed data in any table field.
Just compute it, as above, for display on a form or report.
 
G

Guest

Hi Fred,

I'm not storing the information. This is just a visual reference for the
person using the form to get an idea when he will be done. The thought is if
someone plugs in 8:45 (using short time) the end time will let them know they
can take lunch at 12:15, i.e. 8:45 + 210 minutes or 3.5 hrs.

fredg said:
I am trying to add 210 minutes to whatever start time inputed. I have:
PacerStartTime format property as Short Time and default as 8:30

I tried
Private Sub PacerStartTime_Exit(Cancel As Integer)
Me.PacerEndTime = Me.PacerStartTime + 210
End Sub

I receive the error "The value you entered isn't valid for this field."
What am I missing?

Assuming [PacerStartTime] is a valid Date datatype field, then

Me.[PacerEndTime] = DateAdd("n",210,[PacerStartTime])

As long as your table is storing [PacerStartTime], there would be no
need to store this computed data in any table field.
Just compute it, as above, for display on a form or report.
 
F

fredg

I found initial problem to resolve the error, but it is not adding 210
minutes. It places 7/28/1900 8:30:00 AM in PacerEndTime

Your original post has been answered.
At to why you're getting 7/28/1900 8:30:00 AM using your calculation,
Access has added 210 days to the date stored in your field.

Access dates are stored as the number of days since 12/30/1899.
Access times are stored as the percent of 24 hours elapsed since
midnight of that day.
A Time field must also include a date. So if you have stored the time
as 8:30:00 AM, it's actually stored as 0.354166666666667 (0 is the
date while .3541666...) is the percent of the day.

By default, if you add a DateTime field by a number ([PacerStartTime]
+ 210), Access assumes 210 days.
12/30/1899 + 210 days = July 28, 1900
Therefore you must use the DateAdd () function and specify minutes, as
in my other reply, i.e. DateAdd("n",210,[PacerStartTime]), "n" being
the minute specification.

Look up the DateAdd function in VBA help.
I hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top