Results 1 to 3 of 3
  1. #1
    JJPetersen1 is offline Novice
    Windows 8 Access 2016
    Join Date
    Jan 2020
    Posts
    15

    Query Problem?

    I have a date field (StartDate). In a query I created a field to extract the year from that field .. vYear: DatePart('yyyy',[StartDate])



    This works fine. When I run the query, only the year shows, which is what I want.

    What I want to do is have the user enter a year to pull that data. So I placed [Enter Year] in the Criteria.

    When I run the query nothing appears.

    What am I doing wrong?

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Try Year(StartDate)

    Edit: However it works fine for me?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    It should work. Show your complete SQL statement. Alternative is Year() function.

    SELECT * FROM table WHERE Year([StartDate]) = [Enter Year];

    I never use popup input parameters because cannot validate user input. They could type anything including letters in which case results will be wrong and frustrate user. Refer to form control for user input and validate user input before running query or opening form or report or whatever. I never use dynamic parameters in query at all. I prefer to apply filter to form or report.

    Users shouldn't interact with tables and queries, only forms and reports.
    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. Replies: 9
    Last Post: 07-02-2022, 08:08 PM
  2. Query problem
    By Traceyann1964 in forum Queries
    Replies: 2
    Last Post: 01-20-2016, 07:29 AM
  3. Update Query Problem (Not an Updateable Query)
    By McArthurGDM in forum Queries
    Replies: 6
    Last Post: 02-19-2015, 11:25 AM
  4. problem in a query
    By azhar2006 in forum Queries
    Replies: 1
    Last Post: 12-04-2013, 03:28 AM
  5. query problem i have a problem wi
    By maxx3 in forum Queries
    Replies: 0
    Last Post: 06-29-2009, 02:29 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