Results 1 to 8 of 8
  1. #1
    jainkamleshd is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2016
    Posts
    5

    Dmax calculation, based on Date criteria

    Hello,
    I am new to this forum.

    I want to find Max no (DO_Number) after a certain date, say 31/03/2019.

    I am trying through below qry.

    Expr1: Nz((DMax("DO_Number","tblDOOutward","[Our_DO_Date] > #31/03/2019#")),0)


    On 31/03/2019, my Last DO_Number was 1678 but w.e.f. 1st April, i want to restart from number 1

    Help shall be appreciated.
    PS : I am not a professional programmer but learnt it from net/other sources..

    Regards,
    Kamlesh Jain

  2. #2
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,158
    That looks pretty good to me - what problem are you getting ? Error message ? Wrong result ?

    You do have some extra brackets, try ;

    Code:
    Expr1: Nz(DMax("DO_Number","tblDOOutward","[Our_DO_Date] > #31/03/2019#"),0)
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    jainkamleshd is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2016
    Posts
    5
    Thanks for prompt reply.
    Tried your query but its giving wrong result. It still giving max Do_Number as 1678 only. Sample data as under :

    Our_DO_Date DO_Number
    28/03/2019 1676
    29/03/2019 1677
    31/03/2019 1678
    01/04/2019 1
    02/04/2020 2

    So my qry shall result = 2 and not 1678
    Hope i am able to explain my problem.
    Regards.
    Kamlesh Jain

  4. #4
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,158
    Hmm interesting - Is DO_Number a number or text ?
    And is Our_DO_Date a date field and not text ?

    Also try #2019/03/31# as the date...
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    jainkamleshd is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2016
    Posts
    5
    Thanks Minty.

    1. DO_Number is Number Field
    2. Our_DO_Number is Date Field
    3. We (In India) use date format as DD/MM/YYYY only.

    Shall i try with :
    [Our_DO_date] > #" & Format(Me!Our_DO_Date, "yyyy\/mm\/dd") & "#)
    ?

  6. #6
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,158
    Quote Originally Posted by jainkamleshd View Post
    3. We (In India) use date format as DD/MM/YYYY only.

    Shall i try with :
    [Our_DO_date] > #" & Format(Me!Our_DO_Date, "yyyy\/mm\/dd") & "#)
    ?
    Yes definitely - it may be the date formatting is tripping you up.
    We have the same issues with UK dates.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  7. #7
    jainkamleshd is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2016
    Posts
    5
    Well i tried below :

    Me!DO_Number = Nz((DMax("DO_Number", "tblDOOutward", [Our_DO_Date] > Format(#3/31/2019#, "yyyy\/mm\/dd"))), 0) + 1

    But its giving result as 1 only wheras result shall be 2+1 = 3
    What can be the cause ?
    Help please.

  8. #8
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,158
    I have just tested with both DMax and DMin on a sample table in the immediate window, and got the correct results;

    Code:
    ? DMax("[Empl_Numb]","Table1","StartDate > #" & Format (#16/09/2016#,"yyyy/mm/dd") & "#" )
     10200 
    
    ? DMin("[Empl_Numb]","Table1","StartDate > #" & Format(#16/09/2016#, "yyyy/mm/dd") & "#") 
     10047
    So something else is wrong here.

    Get rid of the Nz function, and remove the extra brackets. Try the DMax in the immediate window first to get the right result.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 8
    Last Post: 01-10-2016, 11:51 AM
  2. Replies: 12
    Last Post: 12-25-2015, 12:47 AM
  3. Date month calculation based on combo box
    By wnicole in forum Access
    Replies: 4
    Last Post: 10-27-2013, 08:04 PM
  4. Replies: 6
    Last Post: 07-24-2012, 03:02 PM
  5. Field content based on date calculation
    By jlmnjem in forum Programming
    Replies: 6
    Last Post: 09-23-2010, 10:24 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums