Solved

Access Query to Get Values

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

773 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