How do I display the most recent of three dates in an Access quer.

How do I display the most recent (or latter) of three dates in an Access query?
3/25/2010 8:07:03 PM
access.queries 6343 articles. 1 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 51

I'm assuming that the date field is truely a date/time datatype and not a 
text field with something that looks like a date.

1. Create a query and sort on that field in descending order. Run it to make 
sure it looks correct.

2. Open the query in SQL view. Change where it says SELECT to SELECT TOP 3  

One caution: If there is a tie for 3rd place, Access will show all the tied 
Jerry Whittle, Microsoft Access MVP 
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.

"Claudia1220" wrote:

> How do I display the most recent (or latter) of three dates in an Access query?
3/25/2010 8:12:01 PM
"How" depends on "what", as in "what does your data/table structure look 


Jeff Boyce
Microsoft Access MVP

Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer

"Claudia1220" <> wrote in message
> How do I display the most recent (or latter) of three dates in an Access 
> query? 

3/25/2010 9:25:19 PM
Assumption: You have three date fields in one record (row).

The best way would be to redesign your table structure to store the dates as 
separate related records in another table.  Or use a union query to fix the data.

The easiest way is to use a VBA function - especially if you have no control 
over the data being supplied.  Below is a function that should work for you. 
In your query you would have a calculated column.
Field: LastDate: fGetRowMax([DateOne],[DateTwo],[DateThree])

Copy this function into a VBA module in your database.  Save the module with 
some name other than fGetRowMax.

Public Function fGetRowMax(ParamArray Values()) As Variant
'John Spencer UMBC CHPDM
'Last Update: April 5, 2000
'Returns the Maximum of a group of values passed to it.
'Sample call:
'   fGetRowMax("-21","TEST","2", "3","4","5","6","7",0) returns "TEST"
'   fGetRowMax(-21,2,3,4,5,6,7,0) returns 7
' Handles text, date, or number fields -
' only one type of data should be passed in
' Max of 29 values if called from a query.

Dim i As Long, vMax As Variant
vMax = Null

    For i = LBound(Values) To UBound(Values)
       If IsNull(Values(i)) = False Then
          If Values(i) <= vMax Then
             vMax = Values(i)
          End If
       End If

    fGetRowMax = vMax

End Function

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

Jeff Boyce wrote:
> "How" depends on "what", as in "what does your data/table structure look 
> like"?
> Regards
> Jeff Boyce
> Microsoft Access MVP
3/26/2010 12:55:28 PM

Similar Artilces:

Access 2007 Upgrade Problems
Help! A couple of years ago I created an assets database using Access 2003. Recently our computers were upgraded to Office 2007. I have been using my assets database using the new Access 2007 and have updated and changed a lot of objects. For the most part, it works OK. One thing I tried that did not work is saving my assets database as an Access 2007 database. When I try, I get a warning message telling me that all open objects must first be closed before the conversion can take place. The same warning dialog asks me if I want Microsoft Offfice Access to close the objec...

Dual Displays
I want to connect my Sharp Aquos flat screen TV to my computer, and see my desktop on both the TV and computer monitor. Windows Vista Home Premium. HP Pavilion a1610n computer. Galaxy GeForce 8400 GS graphics card, outputs: 1-VGA, 1-DVI, and 1-SVGA. There is no HDMI port on the card. I connected a VGA cable between the motherboard "on-board" VGA port and the TV, figuring that I could use that output to work with the TV. The computer monitor is plugged into the GeForce graphics card. Tried the Desktop "Display Setting". It says, the number 2 monitor is "N...

How to handle blank date and time?
I use MFC Visual C++ 4.2 I am developing a database application using MS Access 2000. The problem I am dealing with is how to handle if the user does not enter the date. There is a condition where they can do that for Finish Process Date / Finish Process Time. I make the Date and Time as separate fields, both in the database and the application. On my application I use the COleDateTime data type. I have to save the blank Date and the blank Time, and I also have to acquire them back in order to display the data using the CListCtrl. What I am confusing is how to make the query? Is it...

how can I add 'date modfied' into a cell in excel 2002
as above Check out In article <>, "Shmoo" <> wrote: > as above Thanks JE, appreciate that. "JE McGimpsey" wrote: > Check out > > > > In article <>, > "Shmoo" <> wrote: > > > as above > ...

Access Email
Is there a way to get around the security popup messages that Outlook comes up with when access send a email, have looked around and can only find addins the i want to try and stay away from to make it a simplier process. Been looking at various sites and this keeps coming up 'Object model guard'. Would like to have access take care of the email and outlook problems. The reason why i want to use outlook is that i have records stored in outlook that a email has been sent. Thanks -- Take a look at An add-in such as Outlook ...

Display a message box "this entry is a duplicate"
How can I display a message box on a form if the shipment number is a duplicate? I need a message box to pop up when user attempts to tab out of the field. Thank you. Something like: Private Sub txtShipNum_BeforeUpdate(Cancel As Integer) If DCount("*", "MyTable", "ShipNum = '" & Me.txtShipNum & "'") > 0 Then Msgbox Me.txtShipNum & " already exists." Cancel = True End If End Sub This assumes that your text box is named txtShipNum, that the name of the field in table MyTable is ShipNum...

Folder could not be displayed
I am running Windows XP and Outlook Express 6 just fine then one day my husband does something to my computer and his email account won't work. My email is working just fine but in his he cannot open his inbox. It says folder could not be displayed, and when you send and receive it gives you this error message: "An unknown error has occured. Account: ''. Server:''.Protocol:POP3, port: 110, Secure(SSL): No, error number: 0x800C013B" If anyone could help me with this I would greatly appreciate it. Thank you T...

how to display values in 3 cells into one cell
Anyone can help me how do I display the 3 separate different values in 3 cells into just one single cell ? thanks so much in advance. Either there was a typo or there's an echo in here. That line should have been: = A1 & " " & B1 & " " & C1 "Bradley Dawson" <> wrote in message news:l464b.2224$ > In the target cell, type: > > = A1 & B1 & C1 > > where A1, B1, C1 are the cell addresses that you want to concatenate. > > If these have number...

How to select & display distinct values
Hello, I need help with a form please. My form has two controls, the first being a combo box. This box should select the company name from a lookup table. The lookup table has only two companies in it, however, they each are repeated several time. Company 1 has about 10 rows, company 2 has 3 rows. I used the query builder and came up with the statement: "SELECT DISTINCT Lktbl_Role_Master.CompanyName FROM Lktbl_Role_Master;" When I run the statement directly from query view, it executes perfectly and returns exactly two rows (one for each company, in a datasheet view) ho...

find and count days in blocks of consecutive dates
I need to find a way using Excel to find blocks of consecutive dates in a list and then count how many days are in each block. Any help is appreciated. Hi if i'm understanding you correctly, you can use the COUNTIF function =COUNTIF(range,">="&datevalue("lowest_date"))-COUNTIF(range,">"&datevalue("highest_date")) e.g. =COUNTIF(A1:A23,">="&DATEVALUE("2/10/04"))-COUNTIF(A1:A23,">"&DATEVALUE("4/10/04")) counts all the days between 2/10/04 and the 4/10/04 inclusive PS you might nee...

Display Time in Outlook
The time setting in my Outlook is one hour behind my actual time. I cannot determine how to change the time. Outlook is the only item that is incorrect. Other display times in operating system are correct. Thanks, Jodi ...

Remotely viewing event log without full access to server
Hi, I'd like to know if it is at all possible to allow a domain user to access the event log on a remote server (say server 2003 standard or 2008 R2) but not have the ability to log into the server itself. For example, to allow someone to monitor the server logs but not allow them to make any changes to the server itself. Much appreciated. "Mehdis" <> wrote in message > Hi, > > I'd like to know if it is at all possible to allow a domain user to acce...

Statement Date
I enter my transactions manually for some of my accounts, ie utility bills. These transactions always have different payment dates, statement closing dates, service dates, etc.. Is there any way to enter the statement date on money 2007 deluze version I would like to do this so that I know what month I have just paid. In, OfficeNDN wrote: >I enter my transactions manually for some of my accounts, ie utility bills. > >These transactions always have different payment dates, statement closing >dates, service dates, etc.. > >Is there...

Microsoft Web Access E mail
This is a quirky problem that I hope someone can help me with. I am a remote home office in the NE and I work for a facility in NC. I receive and send my E mail through Microsoft Web Access Mail. So another words, I type I get a dialoge box, put in my username and password and up comes outlook. OK. The problem I have is that in the body where I type my e mail message I can not right click to do things like Copy and Paste. I click on the "right" mouse button and nothing happens at all. I simply can not right click. If I right click anywhere else on t...

PK and FK Displayed
I am a complete Visio newbie, and cannot find the answer I need in books or online help. I am trying to create ER diagrams from scratch, and not connected to real tables, using VEA. I have added tables ('Entities') to the form, connected them with a Relationship connector, and, in the Database Properties window I've assigned the end points to a Primary Key on the left and a Foreign Key on the right. But the model shows the connector as running between the top colums on both sides, whereas I want the keys to be in that upper box and provide the connector's end points. Wh...

Money 2007 -- QIF import
Good Evening! After a little trial and error, I am able to import account transactions from another system (not a bank statement, my actual register transactions) with little trouble except for the date format. (Before someone gets mad at me, I really don't think this has anything to do with my regional settings!) As recommended by an MVP from this forum, I open my CSV file with excel, then use a converter (add-in) called XL2QIF to create a qif output file. The actual "data" in a date field in my original csv file is "060106" (mm/dd/yy) which is June 1, 2006,...

Date validation #3
hello everybody, i am new to excel , and i want to format a particular cell such that it accepts a date and the date should BE ONLY SATURDAY. If the date is not saturday a message box should appear and say "please enter the correct date". Please let me know step by step.As i am not comfortable using excel. Thanx, Ragini. ------------------------------------------------ ~~ Message posted from ~~ View and post usenet messages directly from Ragini, Use Data Validation, setup a custom criteria, and use a formula of =WEEKDAY(A1)=...

Formulas are displayed, results are not
Hello, For some reason, when I enter a formula into a cell and press enter, the formula just stays there. Anyone know what I can do to show the results? I tried pressing Cntrl + `, but that didn't work. FYI, when I cut and paste a column from a separate workbook, that column works like normal (i.e., the formulas produce results). Thanks for any suggestions! Hi Mike, Maybe your cell is preformatted as Text. Try formatting to general then erase your = and type it in again. HTH Martin "Mike C" <> wrote in message news:f699bcd4-ad82-4a88-9759-5638c147b...

MS Access connection
I've been trying for awhile to get the code below to "work" but alas nothing seems to update the table in the database. I have a button on a page which when clicked should insert a new record into the database...all of this just to test that I am doing correctly (or at this point doing something wrong). Any suggestions on why a record never gets inserted? <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional...

Stop displaying a line
I have a line graph/chart and it gets its values using a formula and the values of another column. However this poses a problem because if there is nothing in the targetted column the formula returns 0 cause the line to drop to the bottom, instead of casuing the line to just end until a value is added to the target column. How can I do this? Change your formula to use NA() if the cell is empty. For example: =IF(A1="",NA(),A1) To hide the resulting #N/A errors on the worksheet, you can use conditional formatting. There are instructions here:

unattached textboxes disappear when a msgbox is displayed on a tab control
I'm using Access 2003. I have a form with a tab control on it. I was having problems with labels flashing and I followed the suggesting from Allen Browne - The flashing went away but now when a msgbox is displayed the unattached textboxes that I'm using as labels disappear. They come back as soon as the msgbox is removed from the screen. I've searched google looking for an answer but have come up short. Does anyone know why I'm experiencing this behavior and how to make it go away? Thanks, Rick That *is* strange. Have you tr...

A question about Console window(display or not display)
I've redirected the (stdin stdout stderr) of a console window process I spawned to a pipe. And I want to display the redirected console window, the question is: If I display it(set Create_new_CONSOLE in createprocess and some flags in startupinfo), I cannot use the redirected way of pipe, which means if i do not display, i can use the pipe communicating with the child process. Does it mean that as long as I disply the console window, windows will change stdin stdout to "screen&keyboard" instead of my pipe? That's right. If you redirect stdin or stdout then you preemp...

Access Calendar to Julian Conversions
I have a database with dates in the MM/DD/YYYY format and I need to convert them to julian dates. Is there a built in function in Access that will do this? Depends what you mean by "Julian Date". If you'll looking to represent the date as the day number in the year, (yyyy.ddd, so that today is 2004.177), try: Format(MyDate, "yyyy") & "." & Format(Format(MyDate, "y"), "000") -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Dave" <> wrote in message news:217...

Counting against a date
Hi I want to count the rows in a range 'Tests 1' AF3:AF1000=YES if the date in the range 'Tests 1' AD3:AD1000 is (<=) less than or equal to the date in B14 (current sheet) using the following formula: =IF($B14="","",(SUMPRODUCT(('Tests 1'!$AF$3:$AF$1000=YES)*('Tests 1'!AD$3:$AD1000<=$B14)))) unfortunately this returns an #N/A error I'm clearly missing something here so any tips or pointers would be appreciated. -- Steve Sometimes I think we're alone. Sometimes I think we're not. In either case, th...

Display or not display series
I have a graph with four series but some of the series may be blank, i.e. the series name is <blank series>. Is there a way to not display these series on the graph and/or legend if they are blank, and display them if they are without deleting the series? Thanks! Clay Create a chart from all the data Select the data on which the chart is based. Choose Data>Filter>AutoFilter In the heading cell for the series name column, select (NonBlanks) from the dropdown list The series with blank name cells will be hidden in the chart. Clay wrote: > I have a graph with four serie...