Results 1 to 9 of 9
  1. #1
    crimedog is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    141

    DMAx Question for Report - DMax <= Dtae

    I have a report with a TextBox formatted as Short Date - the TextBox [Txt12] contains:


    Code:
    =DateSerial(Year(Date()),12,1)
    in the Data Control Source
    for My DMAX In another TextBox I have:
    Code:
    =DMax("[Revquota]","[Qury1TestQuotaby5]","[DateOfChange]<=" & [Txt12])
    There is a Record for [DateOfChange] @ 11/1/2014 this is the record that should be returning the [RexQuota] - the Report shows blank

    I used Month() to return the Month Numbers - and I get a result, but the problem is: there will be more than one year of data - so in the previous example, if there was a record on 12/1/2013 I would not want that returned.
    ([DateOfChange] is a Date/hour format in the Table)

    Hope this is clear - I will of course have a follow up after this.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    What data do you want to consider - all for a specific year?

    =DMax("[Revquota]", "[Qury1TestQuotaby5]", "Year([DateOfChange])=" & Year(Date())
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    crimedog is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    141
    the last date that is before the date in Txt12 - there is a summary for the year with January - December ([Txt1]-[Txt2]) there is not a query entry for each month - just when the info changes. so it needs to return the data for the last time the information changed (before the date in Txt1 etc...)

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    You don't want the maximum Revquota, you want the Revquota value from the latest date prior to 12/1/2014.

    =DLookup("[Revquota]", "[Qury1TestQuotaby5]", "[DateOfChange]=#" & DMax("DateOfChange", "[Qury1TestQuotaby5]", "DateOfChange<=#" & [Txt12] & "#") & "#")
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    crimedog is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    141
    Man that looks right. I copied and pasted - it kicked out error, think I fixed it
    Code:
    =DLookUp("[Revquota]","[Qury1TestQuotaby5]","[DateOfChange]=" & DMax("[DateOfChange]","[Qury1TestQuotaby5]","[DateOfChange]<=#" & [Txt12] & "#"))
    Now it just shows blank. [Txt12]= 12/1/2014 there is a [Revquota] with [DateOfChange]=11/1/2014 - so it should have returned that entry (75,000)

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Looks like you read my post before my last edit. Check it again.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    crimedog is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    141
    Working like a charm! One more question, now to Sum all the entries that are in month & year of [Txt12]
    Code:
    =DSum("[RepRevenue]","[QuryTestRepDeals]"," Format([OrderDate], 'mm/yyyy') = " & Format([Txt12],"mm/yyyy"))
    What am I missing? What was the purpose of the #'s from before?

    Thanks for the help - the lookup is just what I wanted.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Text fields require apostrophe delimiters for parameters, data/time requires # character, number doesn't use any.

    Format function returns a string value.

    =DSum("[RepRevenue]","[QuryTestRepDeals]", "Format([OrderDate], 'mm/yyyy') = '" & Format([Txt12],"mm/yyyy") & "'")
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    crimedog is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    141
    Perfect - Thanks again!

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

Similar Threads

  1. DMax Question
    By The Professor in forum Forms
    Replies: 3
    Last Post: 02-05-2013, 08:30 AM
  2. Replies: 6
    Last Post: 07-24-2012, 03:02 PM
  3. How to use DMAX
    By tomneedshelp in forum Access
    Replies: 2
    Last Post: 03-01-2012, 07:22 AM
  4. using a qry to run a report with Dmax Function
    By mrjoshuaw in forum Access
    Replies: 6
    Last Post: 02-01-2012, 07:29 AM
  5. Using Nz and Dmax
    By timmy in forum Programming
    Replies: 5
    Last Post: 07-04-2011, 06:42 AM

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