Results 1 to 5 of 5
  1. #1
    steveabni is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2014
    Location
    Chicago
    Posts
    6

    Date Query: Annual Data Based off of Form Date

    Hello Everyone,
    I've built a crosstab query and what I'd like it to do is only pull in data for the year that is selected from a form. I thought I had the where clause written correctly, but the query ends up displaying all records instead of the year based on the date in the form.

    PARAMETERS [forms]![Main Menu]![End Date] DateTime;
    TRANSFORM Avg([Stock Adjustments].Cost) AS AvgOfCost
    SELECT [Stock Adjustments].Whse, Avg([Stock Adjustments].Cost) AS [Total Of Cost]
    FROM [Stock Adjustments]
    WHERE ((Year([forms]![Main Menu]![End Date])=Year(Date())))
    GROUP BY [Stock Adjustments].Whse


    PIVOT [Stock Adjustments].[Manual Log];

    If someone can point me in the right direction I'd appreciate it.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,950
    The WHERE must reference a field to apply filter to.

    WHERE Year([End Date])=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
    steveabni is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2014
    Location
    Chicago
    Posts
    6
    June7,
    Thanks for the reply. When I changed that line of the query I received a message that stated [End Date] wasn't recognized by the db engine. I entered [End Date] into the parameters area and then recieve a prompt to enter the End Date.

    Is there a way to write this so it returns records of the year that's entered on the form?

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,950
    What is name of the field with the date value?

    WHERE Year([fieldname])=Year([forms]![Main Menu]![End 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.

  5. #5
    steveabni is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2014
    Location
    Chicago
    Posts
    6
    That was it......Thank you again for your help June7, I appreciate it.

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

Similar Threads

  1. Replies: 1
    Last Post: 11-26-2013, 09:25 AM
  2. Replies: 2
    Last Post: 03-07-2013, 03:14 PM
  3. Sum Data Based on Date Field
    By Can5er in forum Access
    Replies: 2
    Last Post: 10-03-2012, 07:19 PM
  4. Replies: 3
    Last Post: 08-21-2012, 03:05 PM
  5. query to update a date based on another date
    By tkendell in forum Access
    Replies: 3
    Last Post: 06-29-2011, 09:32 PM

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