+ Reply to Thread
Results 1 to 6 of 6

Thread: Annual report (between dates)

  1. #1
    Registered User
    Join Date
    04-21-2010
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    54

    Annual report (between dates)

    I'm trying to run anual reports. I have a query setup, and I need to request the Year that the report needs to check on. For now I have been using this:

    Between [Start of Year : like 01/01/2011] And [End of Year : like 12/31/2011]

    as the criteria. I would prefer to just have them enter the year (such as 2012) and then it would use that as the criteria. Any help on how I can build this in the criteria?

  2. #2
    Forum Guru ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    traded up
    MS-Off Ver
    2003 & 2010
    Posts
    1,905

    Re: Getting an anual report (between dates)

    Set up a calculated field in your query as

    DateYear: Year([YourDateField])
    then use it for your year (2012) criteria.

    Cheers,
    “To sin by silence when they should protest makes cowards of men.” ~ Abraham Lincoln

  3. #3
    Registered User
    Join Date
    04-21-2010
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    54

    Re: Getting an anual report (between dates)

    I guess my issue is that the data has a date field. I can't really compare a date to a year... can I?

  4. #4
    Forum Guru davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2007
    Posts
    1,879

    Re: Annual report (between dates)

    Assuming you are capturing the requested year as a variable, say intYear:

    SELECT * FROM yourTable WHERE Year(dateField) = [intYear]
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  5. #5
    Registered User
    Join Date
    04-21-2010
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    54

    Re: Annual report (between dates)

    Can I use that statement in the criteria?

    Right now I have a filed called EOL DATE which poles 2 fields from the original table. The data (put together by a different group) has the date in 1 of 2 fields (depending on if the equipment is purchased or leased). So my EOL DATE field in my query:
    EOL DATE: IIf(Not IsNull([dbo_AM_Assets].[SCHEDULED_RETURN_DATE]),[dbo_AM_Assets].[SCHEDULED_RETURN_DATE],[dbo_AM_Assets].[SUGGESTED_REFRESH_DATE])

    gives back 1 of these dates. I'm just trying to get the flow of how to do this. So I need to make a new field in the query? or just criteria? I'm starting to get confused.

    EDIT:
    Ok, I got it. I made a new query field like this:
    YEAR: Year(IIf(Not IsNull([dbo_AM_Assets].[SCHEDULED_RETURN_DATE]),[dbo_AM_Assets].[SCHEDULED_RETURN_DATE],[dbo_AM_Assets].[SUGGESTED_REFRESH_DATE]))

    Pretty much the same as my date field, but then narrowed it to Year(). Thanks for the help
    Last edited by jik_ff; 11-08-2011 at 04:35 PM.

  6. #6
    Forum Guru davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2007
    Posts
    1,879

    Re: Annual report (between dates)

    In the WHERE clause, you should just be able to add:
    WHERE Year([EOL DATE]) = intYear
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0