Function to return earliest date

Joined
Sep 27, 2005
Messages
6
Reaction score
0
I have the following date fields in a query; MCSOneNew, PartAMCS, PartBMCS, PartCMCS.
There will always be a date in at least one of these fields.
I need a function that will return the earliest date, regardless of whether or not
all of these dates fields contain values.

I've tried the following query expression: BestDate: MCSParent(MCSOneNew,
PartAMCS, PartBMCS, PartCMCS) and below is the function I'm using to return the earliest date.

The function will return the earliest date, but only if all of the date fields contain a date.
I need it to return the earliest date in the record, even if not all of the 4 date
fields contain a date.
Can someone help me revise my code? Thanks much -

------------------------------------------------------------------------

Option Explicit

Public Function MCSParent(MCSOneNew As Date, PartAMCS As Date, PartBMCS As Date, PartCMCS As Date) As Date

If MCSOneNew < PartAMCS And MCSOneNew < PartBMCS And MCSOneNew < PartCMCS Then
MCSParent = MCSOneNew
'ElseIf MCSOneNew = PartAMCS And MCSOneNew = PartBMCS And MCSOneNew = PartCMCS Then
' MCSParent = MCSOneNew
ElseIf PartAMCS < PartBMCS And PartAMCS < PartCMCS Then
MCSParent = PartAMCS
ElseIf PartBMCS < PartCMCS Then
MCSParent = PartBMCS
Else
MCSParent = PartCMCS

End If
 

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