Solved

Access Query to Get Values

Posted on 2014-07-30
3
229 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

932 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

10 Experts available now in Live!

Get 1:1 Help Now