Solved

Access Query to Get Values

Posted on 2014-07-30
3
228 Views
Last Modified: 2014-07-30
I have an old access 97 database that has multiple fields per record.

Client1_EntryDate
Client2_EntryDate
Client3_EntryDate
Earliest_EntryDate

I want to run a query that can look at the 3 columns, Client1_EntryDate, Client2_EntryDate and Client3_EntryDate then get me the earliest date out of the 3 so that I can update it into the field Earliest_EntryDate field.

so for eg,  if Record 1 had

Client1_EntryDate = 12/07/2001
Client2_EntryDate = 18/01/1998
Client3_EntryDate = 15/03/2005

then I want to update Record1 Earliest_EntryDate with the value of 18/01/1998

This is 1 query that will give me the earliest values. Then I will also want to run a similar query that updates another field but gives me the latest.

Client1_LastDate
Client2_LastDate
Client3_LastDate
Latest_EntryDate

This will opposed to looking at the earliest date will update the record with the latest date.
We are only looking within the record as all fields required to lookup reside within a record.  Please also note that its possible some values will be null which is that case the value will be ignored.

Eg

Client1_EntryDate = 12/07/2001
Client2_EntryDate =  Blank
Client3_EntryDate = 15/03/2005

then I want to update Earliest_EntryDate with the value of 12/07/2001
0
Comment
Question by:GenieMaster
  • 2
3 Comments
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 40229574
I use a function for this.  It accepts as many parameters of whatever type you want to compare and will return the minimum value within that set:

What you should be able to do is:

Update yourTable Set Earliest_Entry = fnMin([Client1_EntryDate], [Client2_EntryDate], [Client3_EntryDate])

you might want to add:

WHERE [Earliest_Entry] IS NULL

Public Function fnMin(ParamArray ValList() As Variant) As Variant

   Dim intLoop As Integer
   Dim myVal As Variant
   
   For intLoop = LBound(ValList) To UBound(ValList)
      If Not IsNull(ValList(intLoop)) Then
         If IsEmpty(myVal) Then
            myVal = ValList(intLoop)
         ElseIf ValList(intLoop) < myVal Then
            myVal = ValList(intLoop)
         End If
      End If
   Next
   fnMin = myVal
   
End Function

Open in new window

0
 

Author Closing Comment

by:GenieMaster
ID: 40229782
Perfect, Just what I needed. Thanks :)
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 40230193
Glad to help.

BTW, really easy to modify that to give you the Max values.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now