Solved

Access Query to Get Values

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
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 how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

696 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