Most recent date ....

  • Thread starter Thread starter Wanda
  • Start date Start date
W

Wanda

I have 6 date fields and I want to be able to have a temp
field that determines the latest date .... is there code
that can do this? I could then link the temp field to
the main page where it is needed. I'm thinking that I
need to use an IF statement, but I am not sure how to do
the logic for that after the first 2 fields.

Thanks.

Wanda
 
Do you have a sample of your code so far that you can show us?

If you want to add a field on the fly, add one to the Item.UserProperties
collection.

To do date comparisons, use the DateDiff function:

Dim date1 As Date, date2 As Date

date1 = #1/1/2005#
date2 = #1/2/2005#

If DateDiff("y", date1, date2) > 0 Then
'If date1 refers to a later point in time than date2, the DateDiff
function returns a negative number.
Debug.Print "date1 is earlier than date2 using day of year as a
comparison"
Else
Debug.Print "date2 is later than date1 using day of year as a
comparison"
End If
 
I don't know why I was making it harder then it needed to
be. I have it working now and instead of using manual
written code, I used code through the objects.

I defaulted all date fields to January 1, 1900. As the
client needs to change the date, I have hidden objects
that look at the first and second date and calculate which
is the latest, then an object that looks at A (first and
second calculation field) and populates B object .... and
so on. The very last object (field) is linked to the
main page with a visible date showing of the latest date
entered. On the hidden objects to do the calculations, I
made the Type = Date, Fomat = Month day, Year ... then
I "set initial value of field to" = IIf( expr ,
truepart , falsepart ), and clicked on the radio
button "calculate formula automatically".

It works like a charm. I'll keep the "DateDiff" in mind
for other forms. Thanks very much.

Wanda
 
Back
Top