Consulting

Results 1 to 5 of 5

Thread: calculated field maximum date

  1. #1
    VBAX Tutor
    Joined
    Nov 2007
    Posts
    291
    Location

    calculated field maximum date

    Hi,

    I have a database table which holds an import file.

    There are three date fields (as well as loads of other fields):-

    Maturity date Final Maturity Date Limit Exp Date


    I want to run a query that pulls a few fields and then a field called "max Date" which has the latest of all three dates.

    In excel you can use the "max" funtion with dates to get the last date.

    I tried this in the expression builder in query designer but with no success.

    Can anyone think of how I can do this?

    (I dont like using custom VBA functions in query design as I find it slow!)

    Cheers
    Phil

  2. #2
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location
    The only way I can think of to do this is using nested IIF statements to compare the three data fields. Something like:
    [VBA]IIF(Date1 > Date2 AND Date1 > Date3,Date1,IIF(Date2>Date1 AND Date2>Date3,Date2,IIF(Date3>Date1 AND Date3>Date2,Date3,null)))[/VBA]

    HTH
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


  3. #3
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    Taking Randy's solution you may well be able to then Max that, I take it you are aware of the Max function in access queries under "Totals"?

  4. #4
    VBAX Tutor
    Joined
    Nov 2007
    Posts
    291
    Location
    Hi Guys,

    Thanks for that.

    Would I need to use the Max function in a totals query after using Randy's answer. Randy's will seem to give me the latest date per record which is what I was after.

    The Max selection in a totals query will only give me the Max date in a grouping, no?

    Cheers guys

  5. #5
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    As you say it will only give you the Max date if you have a group of similar records, it will then find the last date.
    But if Randy's answer does what you want ignore my remark.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •