DateDiff always tests positive ??

T

Terri

I am trying to test between two dates using:

If 2 > DateDiff("d", DueDate, OpenedDate) Then
MsgBox "The due date .......

but it always tests positive no matter what the dates are. Can anyone tell
me what I am doing wrong?

Thank you, Terri
 
D

Douglas J. Steele

How have DueDate and OpenedDate been declared, and how are they getting
their values?
 
T

Terri

They are text boxes on my form both being a medium date that pick up the
current date as a default with the ability to be modified.
 
D

Douglas J. Steele

If they're text boxes, try:

If 2 > DateDiff("d", Me.DueDate, MeOpenedDate) Then

If that doesn't work, try

If 2 > DateDiff("d", CDate(Me.DueDate), CDate(MeOpenedDate)) Then
 
T

Terri

I had tried something similar:

If 2 < DateDiff("d", [Me.DueDate], [Me.OpenedDate]) but recieved an Access
error message not being able to find '|' field in my expression, so I tried
other means. I was able to work with both methods that you suggested and
after some additional testing realized that I was looking for a "-2"
comparison also.

Thank you very much for your help!
 
J

John Vinson

If 2 < DateDiff("d", [Me.DueDate], [Me.OpenedDate]) but recieved an Access
error message not being able to find '|' field in my expression

That's because of misplaced brackets. It's looking for controls NAMED
Me.DueDate and Me.OpenedDate (rather than controls named DueDate and
OpenedDate), since you put the Me. inside the square brackets. Use
Me.[DueDate] instead and this particular problem will go away.

John W. Vinson[MVP]
 
Top