Results 1 to 3 of 3
  1. #1
    BLFOSTER is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2013
    Posts
    68

    Previous Year and Specified Month in Select statement VBA

    I am trying to pull dates via select statement in VBA for the previous year(2013) and month of September. This definitely does not work. Please tell me how to write this if you can!

    "SELECT * FROM MyQuery " _


    & "WHERE [MyDate] Between DateSerial(Year(Date()-1),Month(9),1) And DateSerial(Year(Date()-1),Month((9)),0)"

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    The -1 is misplaced.

    "SELECT * FROM MyQuery WHERE [MyDate] Between DateSerial(Year(Date())-1,9,1) And DateSerial(Year(Date())-1,9,0);"

    If you want only the month of September, consider:

    "SELECT * FROM MyQuery WHERE Year([MyDate])=Year(Date())-1 AND Month([MyDate])=9;"
    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
    BLFOSTER is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2013
    Posts
    68
    Thanks! Works beautifully!

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

Similar Threads

  1. Select Month from previous selected year
    By k0enf0rNL in forum Access
    Replies: 1
    Last Post: 01-15-2014, 12:14 PM
  2. Previous Year Data Query Expression
    By NotReese in forum Queries
    Replies: 4
    Last Post: 11-22-2013, 04:54 PM
  3. Replies: 4
    Last Post: 05-26-2013, 03:28 PM
  4. Query Help - calculate variance previous year
    By brtucker in forum Queries
    Replies: 1
    Last Post: 01-31-2013, 05:40 PM
  5. by year by month
    By nkuebelbeck in forum Reports
    Replies: 21
    Last Post: 03-24-2010, 01:53 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