Results 1 to 12 of 12
  1. #1
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727

    last 12


    All, I have a table with a start date and end date with data going back 5 yrs. In a query; I using between in both criteria to get the data for July 1, 2013 to August 31, 2014. I need to pull this query on a monthly basis and I need to automate for the user to pull the last 12 months. I may only need the end date however I was using this code in the criteria: DateAdd(“m”,-12,Now) but it gave me 9/3/2014 and time for all the records. Help pls.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Maybe you want Date() instead of Now()?
    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
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    Returns no data???

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Post the complete SQL statement.

    Does data have time component?
    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
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    This is my SQL code:

    Code:
    SELECT tblCust.Custid, tblMstr.ScriptName, tblMstr.[WState], tblMstr.[Start Date], tblMstr.[End Date], Sum(tblMstr.[Wages]) AS [SumOfWages]
    FROM tblMstr  LEFT JOIN tblCust ON tblMstr.Custid = tblCust.Custid
    GROUP BY tbl Cust. Custid, tblMstr.ScriptName, tblMstr.WState, tblMstr.[Start Date], tblMstr.[End Date]
    HAVING (((tblMstr.[Start Date]) Between #7/1/2013# And #8/1/2014#));
    I am trying to automate to "Last twelve months" instead of prompting the users for a date. Thanks

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Does the static criteria work? Replacing with dynamic parameters should work but that is not the query you posted.
    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
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    I posted whAt worked if I put a date range n the criteria. But I would like to automate without users input to get the last twelve months. I tried dateadd("mm",12,Now())

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    (((tblMstr.[Start Date]) Between DateAdd("m", -12, Date()) And Date()));

    works for me
    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
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    Thanks. I'll try it tomorrow. Does this go in the criteria section?

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Yes. It should replace the HAVING criteria you show.
    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.

  11. #11
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    Ok It works. But How can I modify it to get the last twelve months but 2 months behind? For ex. I need 7/1/2013-6/30/2014. I tried using this:

    Code:
    Between DateAdd("m",-12,Date() And DateAdd("m", -2,Date()))
    but error says: "You did not enter the keyword and in the Between....And operator". What does this mean??

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Missing paren: DateAdd("m",-12,Date()) AND

    Make sure they are always paired, even number of parens.
    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.

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

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