Results 1 to 11 of 11
  1. #1
    DFeil is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2012
    Posts
    18

    Query to Look for all Records for a single month from Three Months Ago

    The query contains three fields pulled from a main table, the fields are FirstName, LastName and DateofHire. I am looking for an expression in the criteria section of the DateofHire field. I am trying to create a query that will pull all the records from the month three months prior to the current date, whatever that turns out to be. For example from todays date, I would need it to pull all the records from August 2012. Thanks in advance for your help.



    Dave

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    See if these get you started, using the Date() function for the date input (dte):

    'First of previous month
    myDate = DateSerial(Year(dte), Month(dte) - 1, 1)

    'Last of previous month
    myDate = DateSerial(Year(dte), Month(dte), 0)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    DFeil is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2012
    Posts
    18
    Tried that, no luck...

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    What exactly did you try, since an adaptation of those would certainly work?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    DFeil is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2012
    Posts
    18
    I tried pasting the expression (myDate = DateSerial(Year(dte), Month(dte) - 1, 1)) into the criteria field, then ran the query, no joy.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    That was just an example of the useage. You'd just want the formula, and you'd use it in a criteria with Between:

    Between FormulaForFirstOfMonth And FormulaForLastOfMonth

    And like I said, you'd use the Date() function in place of dte.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    DFeil is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2012
    Posts
    18
    You mean like this...
    between dateadd("m",-3,date()) and dateadd("M",-2,date())

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    I suspect that would run without error, but not return what you asked for in post 1 (but it's on the right track).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    DFeil is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2012
    Posts
    18
    It doesn't return anything...

  10. #10
    DFeil is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2012
    Posts
    18
    Thanks for your help, quitting till Monday, have a good weekend.

    Dave

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Can you post the db?
    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. Replies: 6
    Last Post: 10-17-2012, 03:01 PM
  2. First of the Month, Following 2 Months in Query
    By sainttomn in forum Queries
    Replies: 5
    Last Post: 07-06-2011, 03:51 PM
  3. Replies: 2
    Last Post: 08-25-2010, 01:42 PM
  4. Replies: 3
    Last Post: 12-23-2009, 08:50 AM
  5. Replies: 0
    Last Post: 08-04-2009, 08:51 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