Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding the lowest date

Status
Not open for further replies.

Drago1920

Technical User
Jan 8, 2017
6
US
Hello everyone,

I have a database to track employee training, and I have created the module below to find the lowest date from multiple fields. It is working well until the dates are from the previous year. Is there a way to include the previous years? Or please tell me what I did wrong.

Module format

Function FirstLow(D1, D2, D3)
D1 = Nz(D1, #1/1/2999#)
D2 = Nz(D2, #1/1/2999#)
D3 = Nz(D3, #1/1/2999#)

If D1 < D2 And D1 < D3 Then
FirstLow = D1
ElseIf D2 < D1 And D2 < D3 Then
FirstLow = D2
Else
FirstLow = D3
End If

Query

First: FirstLow([LandDate],[HoverDate],[DepDate])



Thank you for your time.
 
The correct values should return regardless of year. I would use:

Code:
Function FirstLow(D1 as Date, D2 as Date, D3 as Date) as Date

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
You want "to find the lowest date from multiple fields" in a table in Access DB, right?

Why not:

[pre]
Select MIN(MyDate) As [red]FirstLowDate[/red] From
(Select MIN([blue]LandDate[/blue]) As MyDate From ATable
Where [green]<some conditions>[/green]
UNION
Select MIN([blue]HoverDate[/blue]) From ATable
Where [green]<some conditions>[/green]
UNION
Select MIN([blue]DepDate[/blue]) From ATable
Where [green]<some conditions>[/green])
[/pre]
[ponder]

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top