What do you mean by "didn't work correctly in my report"?
Where did you put this in the report? That's a pretty complicated IF
statement.
Did you really mean to use <=Dateadd("m", -6, Date) ? This means that the
[CorrectiveDate] is more 6 months or more in the past, not 6 months in the
future, as your original post stated.
As far as I can tell, the syntax of your IF statement is correct. But
because of the OR clauses, you may be getting results that are different than
what you want.
Sabosis said:
Or you could use the following:
if me.[CorrectiveDate] > DateAdd("m", 6, Date()) Then
'do X
else
'do Y
endif
This will give you 6 full months from today, instead of using a # of days..
----
HTH
Dale
:
Hello-
What is the best way to compare two dates using an IF statement in
VBA. On my report, I have a field called "CorrectiveDate". I wantto
use an IF THEN statment to use today's date, and if six months greater
than todays date, then do X, ELSE do Y. What is the best way to write
this out, I have been having troubles....- Hide quoted text -
- Show quoted text -
How about if you need to add a second condition using an AND in the
expression? I have the following expression, but it did not work
correctly in my report.
If ([CorrectiveDate] <= DateAdd("m", -6, Date)) And ([CorrLevelID] =
1) And ([TotalOccurances] < 6 Or [UnpaidTime] < 16) Or
([TotalOccurances] < 4 And [UnpaidTime] < 8) Then
LevelDown = "q"
Else
LevelDown = ""
End If
End Function- Hide quoted text -
Dale-
That is correct. The Corrective Date field in my report should be
compared against current date, and if the Corrective Date is more than
six months ago, then the field in my report called LevelDown should
populate a "q". The LevelDown field is formatted as Wingdings3, so it
actually displays a down arrow in the field. The date isssue is the
first part of the expression as you can see, then it looks at other
report fields to see if additional criteria are met.
The problem I am having is that I am getting a down arrow in the field
when the CorrectiveDate is not six month or more in the past on some
records. I have another expression called LevelUp which does the same
process, but does not use the CorrectiveDate. It works fine, just
evaluating the corrective level and combinations of TotalOccurances
and UnpaidTime. It is the LevelDown that I am having issues with.
Is there a way to break this expression apart and have the expression
qualify the date first as a stand alone expression, then if that logic
is true, move onto the next step and start evaluation the corrective
level, TotalOccurances and Unpaid time combinations as I do for the
LevelUp part of the report? It just seems that once I added the date
part to LevelDown, things got too complicated.......- Hide quoted text -
- Show quoted text -