Time Isue again

B

bob

Hi Again
Here is the issue i did get the expression
IIf(DateAdd("n",[time in], [time out]) Between 0 And -45, 0,
DateAdd("n",[time in], [time out]))
This was from Allen Browne and it will work to a point if the valve is less
then 45 minutes it is showing 0 but if it is greater then 45 it is showing
all the mintues
I need to to start at 1 and go up from there
Time in 12:00:00
Time out 12:50:00
Delay time 45
Total Time 50 min this is what is showing I need It to be 5 Minutes

Thanks for the help
Bob
 
C

Chris O''''Neill

Hi, Bob:

DateAdd() adds an interval to a date. What you want is DateDiff() which
calculates the time interval between two dates. Also, I'd suggest using "<=
45" instead of "Between 0 and 45" just for the sake of simplicity. Finally,
you want [time out] as the second argument and [time in] as the third
argument. That will always give you a positive number. (If you put [time
in] first you'll always get a negative number.)

Here's what you want:

IIf(DateDiff("n", [time out], [time in]) <= 45, 0, DateDiff("n", [time out],
[time in]))

If the 45 minute "delay time" is never going to change, hard coding it as
above is fine. But, if there's a chance "delay time" will ever be something
other than 45 minutes, I'd use a control ([delay time]) so you don't have to
change the code if the "delay time" changes. You can always use Access'
security features to limit who can access the control.

Hope that helps.

Regards, Chris
 
J

John Spencer

I dont see why you are using DateAdd and not DateDiff. I think what you
want is the following

IIf(DateDiff("n",[time in], [time out]) Between 0 And 45, 0,
DateDiff("n",[time in], [time out])-45)



'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
 
C

Chris O''''Neill

You are SO right, John. I forgot the "-45" at the end, so what I told him
would give the full difference between the dates if it's greater than 45.

Mea culpa!

Regards, Chris

John Spencer said:
I dont see why you are using DateAdd and not DateDiff. I think what you
want is the following

IIf(DateDiff("n",[time in], [time out]) Between 0 And 45, 0,
DateDiff("n",[time in], [time out])-45)



'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'====================================================

Hi Again
Here is the issue i did get the expression
IIf(DateAdd("n",[time in], [time out]) Between 0 And -45, 0,
DateAdd("n",[time in], [time out]))
This was from Allen Browne and it will work to a point if the valve is less
then 45 minutes it is showing 0 but if it is greater then 45 it is showing
all the mintues
I need to to start at 1 and go up from there
Time in 12:00:00
Time out 12:50:00
Delay time 45
Total Time 50 min this is what is showing I need It to be 5 Minutes

Thanks for the help
Bob
 
B

bob

You guys are great that is what is needed
thanks alot


John Spencer said:
I dont see why you are using DateAdd and not DateDiff. I think what you
want is the following

IIf(DateDiff("n",[time in], [time out]) Between 0 And 45, 0,
DateDiff("n",[time in], [time out])-45)



'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'====================================================

Hi Again
Here is the issue i did get the expression
IIf(DateAdd("n",[time in], [time out]) Between 0 And -45, 0,
DateAdd("n",[time in], [time out]))
This was from Allen Browne and it will work to a point if the valve is less
then 45 minutes it is showing 0 but if it is greater then 45 it is showing
all the mintues
I need to to start at 1 and go up from there
Time in 12:00:00
Time out 12:50:00
Delay time 45
Total Time 50 min this is what is showing I need It to be 5 Minutes

Thanks for the help
Bob
 
C

Chris O''''Neill

I'm not sure if you saw my reply to an earlier post by you, so I'll repeat it
here. If it's redundant, my humblest apologies! Anyway...

A few other things you should consider in the design of your application:

1. instead of hard coding the value of "delay time" you should consider
adding a control to your form for delay time and then use that in your
formula. For instance, if the control was called txtDelayTime, your formula
would look like this:

IIf(DateDiff("n", [time in], [time out]) Between 0 And Me.txtDelayTime,
0,
DateDiff("n",[time in], [time out]) - Me.txtDelayTime)

The benefit of doing it this way is that you don't have to go digging into
the code should the value for delay time change. You just enter a different
number into the txtDelayTime control and the formula takes care of everything
else.

2. I would take the spaces out of the field, control, and variable names in
your program. Having spaces in names is generally not a good idea (it can
cause problems). To make the names easier to read, capitalize each word
(e.g. Me.txtTimeOut instead of Me.txttimeout). You can also use underscores
(e.g.
Me.txtTime_Out) but I find that rather messy and awkward to work with. It's
all personal preference, of course.

3. You could also use standard nomenclature to make it easier to understand
the
type of variable or control (e.g. intSomething for integers, strSomething
for strings,
txtSomething for a text box control, etc.) Again, this is generally accepted
practice and makes the code easier to read and understand down the road.
For more info on using a standard nomenclature, look here:

http://www.mvps.org/access/general/gen0012.htm

Hope that's helpful...

Regards, Chris
 

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

Similar Threads


Top