Results 1 to 15 of 15
  1. #1
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305

    Is it possible to have a query remove current month's entries?

    Is there an easy way to have a query remove all entries where the entry's date is this month? Meaning it would remove all entries where the month is March and then once it turns to April, March's then appear and April's are hideen/removed

    Any recommendations?

  2. #2
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Assuming you have a date field and data spanning more than a year then you would probably want to ensure you exclude only this years March entries?

    So something like

    SELECT * FROM YourTable
    WHERE (Month([YourDate]) <> Month(Date()) AND Year([YourDate]) <> Year(Date()))
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305
    I have a monthnumber field. Is it possible to do this off of that?

  4. #4
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,446
    I have a monthnumber field. Is it possible to do this off of that?
    only if your data never holds more than 12 months, or your month number contains a year element to identify which year the month refers to

  5. #5
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305
    The data is only ever the current year

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,122
    So Month(Date()) returns the number of the current month, therefore to eliminate those records you would add <>Month(Date()) in the criteria row of your month field.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  7. #7
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305
    So I'm using the following to populate the month number:

    Code:
    MonthNumber: Format([MyDate],"mm")
    So what exactly would I put in the criteria to exclude the current month?

  8. #8
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,446
    So what exactly would I put in the criteria to exclude the current month?

    f
    ormat([MyDate],"mm")<>Format(Date,"mm")

    or

    month([MyDate])<>month(date)

  9. #9
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305
    The query is asking me to input something 'date' whenever I run the query. For both solutions

  10. #10
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,446
    use date(), not just date

  11. #11
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305
    So i used the following code:

    Code:
    MonthNumber: Format([MyDate],"mm")<>Format(Date(),"mm")
    All that does is show January and February dates as -1, and March as 0

    I'm looking for jan to be 1, feb to be 2, and march to filter out altogethr (until we go into April)

  12. #12
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,446
    without seeing your sql it is anyone's guess. You haven't followed the suggestions made

  13. #13
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,122
    You don't write it like that... In the first row of the query designer you add: MonthNumber: Format([MyDate],"mm"). Then in that new calculated field you go to the Criteria row underneath and add: <>Format(Date(),"mm").

    Or you leave it as you have it (MonthNumber: Format([MyDate],"mm")<>Format(Date(),"mm")) and add <>0 (which equals False) or you simply put True (=-1) in the criteria row.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  14. #14
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305
    Quote Originally Posted by Gicu View Post
    You don't write it like that... In the first row of the query designer you add: MonthNumber: Format([MyDate],"mm"). Then in that new calculated field you go to the Criteria row underneath and add: <>Format(Date(),"mm").

    Or you leave it as you have it (MonthNumber: Format([MyDate],"mm")<>Format(Date(),"mm")) and add <>0 (which equals False) or you simply put True (=-1) in the criteria row.

    Cheers,
    That worked!! Thank you!

  15. #15
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,122
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Replies: 2
    Last Post: 02-12-2015, 05:14 AM
  2. Replies: 3
    Last Post: 12-29-2014, 10:14 AM
  3. Replies: 13
    Last Post: 12-13-2014, 08:12 PM
  4. Replies: 6
    Last Post: 05-05-2014, 10:51 PM
  5. Remove Duplicate Entries in Query Design
    By samanthaM in forum Access
    Replies: 1
    Last Post: 10-27-2013, 11:26 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