Results 1 to 4 of 4
  1. #1
    cebrower is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2018
    Location
    Spring Lake, MI
    Posts
    110

    DatePart in query causes error message

    I have several make table queries that use the DatePart function to limit the resulting table. Today all these queries fail with the error message "Invalid procedure call". The query looks like this:



    Field name is YratePart("yyyy",[ReqShipDate])
    Criteria is DatePart("yyyy",Date())

    When it was working it returned all the records where the year in the ReqShipDate field is the current year. If I change it so that the field is [ReqShipDate] and the criteria is >=#01/01/19# and <#01/01/20# it works fine, but then I need to edit all the queries every year on January 1.

    Any thoughts on why this function suddenly stopped working?

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Are there any Null values in the date field? I don't like that method as it requires the function to be applied to every record in the table. Try a criteria of this directly on the date field:

    Between DateSerial(Year(Date()), 1, 1) And DateSerial(Year(Date()), 31, 12)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    cebrower is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2018
    Location
    Spring Lake, MI
    Posts
    110
    Your suggestion works fine - thanks. I still don't understand why the DatePart thing throws an error. There are no nulls in the table and it has worked for years until this morning. Anyhow, thanks again.

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help. I'm not sure either, but the new way is more efficient anyway.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Help With a Query - Datepart
    By zeusads in forum Access
    Replies: 4
    Last Post: 04-04-2017, 09:14 AM
  2. Replies: 2
    Last Post: 08-04-2016, 03:36 PM
  3. Replies: 7
    Last Post: 03-17-2016, 05:53 PM
  4. Replies: 14
    Last Post: 03-31-2015, 05:20 PM
  5. Replies: 10
    Last Post: 01-07-2014, 04:03 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