+ Reply to Thread
Results 1 to 4 of 4

Thread: Query for a year of data

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

    Query for a year of data

    Not sure how to look this up, but I am trying to streamline a lookup I have made on a large amount of data.

    The data has a date field that is stored in the usual way (dd/mm/yyyy). In a query, I would like to is prompt the user to put in a year, and the query would return items with the year between Jan 1 [year] and Dec 31 [year].

    is it possible to do this? can you partially input a date criteria and sub in the date with a prompt?

    I've tried a few things but I have not done something like this before. He is what I have tried to just get 1 month to work, but no success:

    = 1/31/[YEAR]
    = #1/31/[YEAR]#
    = "1/31/"&[YEAR]

    Also, would it take 1 input to be used 2 times if I used the same name in the []s?
    (such as =between [YEAR] and [YEAR])
    Last edited by romperstomper; 07-08-2011 at 05:39 PM. Reason: Mark solved

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

    Re: Query for a year of data

    Hi,

    In your query, create a calculated field like:

    dateyear: YEAR([yourdatefield])
    change the "yourdatefield" to the name of your date field.

    then set the criteria for that field as a parameter like:

    [Enter the four digit year]
    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: Query for a year of data

    I will give that a try, but I found the solution. It goes back to math class, and understanding that you can change both sides of the equation (either side of the equal sign).

    What I did was to go into the button that calls up the query and set the "Where" claus to :

    Year(<datefield from the query>) = [Check Which Year]

    This way it sees to be looking at the year part only of that field in the query and only shows those that match the year entered.

    But learning different ways to do things always inproves my outlook on all coding, so thanks for the reply. I will try that out.

  4. #4
    Registered User
    Join Date
    12-18-2010
    Location
    UK
    MS-Off Ver
    2003, 2007, 2010
    Posts
    79

    Re: Query for a year of data

    Hello

    Another way is to use this as your criterion for your date_field:

    DatePart("yyyy",[date_field_name])=[Please input year]
    David
    Access and Excel Developer | UK

+ 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