Results 1 to 13 of 13
  1. #1
    Kirsti is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172

    Financial Year Query Help

    Hi,



    I have a query where the criteria is based on an unbound form which holds the dates for the current Financial Year. It then also takes data for <Month(Now()). I noticed that even though the dates in frmFinancialYear are from 01/07/2011 to 30/06/2012, the data for 2011 is not coming through. If I take out the <Month(Now()) criteria the query works as expected showing data for 2011 and 2012.

    Then to test, I tried Month(Now())-6, and this did not bring through December 2011 data either.

    Does anyone have any idea why this would be?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Review this for possible cause http://allenbrowne.com/ser-36.html
    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
    Kirsti is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172
    Thanks June,

    I have looked though, and in my tables and forms, I have all date fields set to 'Medium Date' to try to avoid that issue.

    I still haven't managed to figure it out, so any other suggestions greatly appreciated.

    Kirsti

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    The conflict with international dates is the only thing I could think of. It came to mind because you show the dates in the day/mon/year arrangement in your post.

    Do you want to provide file for analysis? Follow instructions at bottom of my post.
    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
    Kirsti is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172
    Thanks June, database attached.

    Kirsti
    Attached Files Attached Files

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    I removed expression from ControlSource for each date textbox so I could select from the date picker. The queries work as designed.

    December 2011 did not return because Month(Now())-6 = 0 (assuming Now is June). 12 is not less than 0. Month(Now())-7 = -1. See what is happening?

    Change the Month expressions to:
    Year([tblMediation_Tenancy_Tribunal_Activity_ALLDATA.Dat e_Application_Lodged) & "/" & Format(Month([tblMediation_Tenancy_Tribunal_Activity_ALLDATA.Dat e_Application_Lodged]),"00")

    Year(Now()) & "/" & Format(Month(Now()),"00")

    If you want to subtract months:
    Year(DateAdd("m",-6,Now())) & "/" & Format(Month(DateAdd("m",-6,Now())),"00")
    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
    Kirsti is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172
    Thanks June,

    I am trying to use your syntax but getting an error: "The expression you entered contains invalid syntax, or you need to enclose your text data in quotes".

    It seems to thing the "00" at the end is text?

    Are you able to post back the DB I posted that you tested with?

    Thanks, Kirsti

  8. #8
    Kirsti is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172
    Also, yes, what you say about 12 not being less than 0 makes perfect sense. Thanks.

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Here is the working SQL statement. Paste it into SQL View of query designer (fix the extraneous spaces the website threw in at Housing_Officer and Date_Application). Enjoy.

    PARAMETERS [Forms]![frmFinancialYear]![dteF1] DateTime, [Forms]![frmFinancialYear]![dteT1] DateTime;
    SELECT tblMediation_Tenancy_Tribunal_Activity_ALLDATA.Hou sing_Officer, tblMediation_Tenancy_Tribunal_Activity_ALLDATA.Arr ears_Current, Date() AS [Report Date], IIf([Arrears_Current]=-1,1,0) AS Total, tblMediation_Tenancy_Tribunal_Activity_ALLDATA.Dat e_Application_Lodged
    FROM tblMediation_Tenancy_Tribunal_Activity_ALLDATA
    WHERE (((tblMediation_Tenancy_Tribunal_Activity_ALLDATA. Arrears_Current)=True) AND ((tblMediation_Tenancy_Tribunal_Activity_ALLDATA.D ate_Application_Lodged) Between [Forms]![frmFinancialYear]![dteF1] And [Forms]![frmFinancialYear]![dteT1]) AND ((Year([tblMediation_Tenancy_Tribunal_Activity_ALLDATA.Dat e_Application_Lodged]) & "/" & Format(Month([tblMediation_Tenancy_Tribunal_Activity_ALLDATA.Dat e_Application_Lodged]),"00"))<Year(DateAdd("m",-7,Now())) & "/" & Format(Month(DateAdd("m",-7,Now())),"00")));
    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.

  10. #10
    Kirsti is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172
    Wonderful, thanks June.

    I actually need 2 versions of this code. One to bring back all records in the previous month, which I have been able to achieve using the code you posted above. (The Month(Now())-7 was just an example, as I was trying to test how the code would work when running it in Jan, to bring Dec results). So this bit is now working - Thank you!

    The second version I need, is to bring back all records in the financial year, excluding the current month's data. I tried to achieve this by playing with your code, with no success. Are you able to show me what this code would look like?

    I really appreciate your help.

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Wouldn't the criteria simply be: <Year(Now()) & "/" & Format(Month(Now()),"00")
    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.

  12. #12
    Kirsti is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172
    Perfect, thanks again June.

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    You could possibly make one query serve for both. Use a query input parameter in the criteria for the months to subject. The input could be reference to another textbox on form.

    <Year(DateAdd("m",-Nz([Forms]![frmFinancialYear]![tbxMonths],0),Now())) & "/" & Format(Month(DateAdd("m",-Nz([Forms]![frmFinancialYear]![tbxMonths],0),Now())),"00")
    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.

Similar Threads

  1. Financial Year not Calendar Year
    By Kirsti in forum Queries
    Replies: 5
    Last Post: 05-02-2012, 09:11 PM
  2. Replies: 4
    Last Post: 01-10-2012, 06:26 PM
  3. Financial Query
    By Luke in forum Queries
    Replies: 8
    Last Post: 06-30-2011, 12:33 PM
  4. Replies: 1
    Last Post: 07-12-2010, 12:00 PM
  5. Date manipulaton for Financial Year
    By Neil Bingham in forum Access
    Replies: 0
    Last Post: 02-15-2009, 11:24 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