Results 1 to 10 of 10
  1. #1
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186

    Usage of Me.Filter between two dates

    Hello everybody,

    I have in my form (from a query) two unbound fields named "StartDatetxt" and "EndDatetxt" and I want to filter all the records that are between such dates, but this is not working as if. Basically it's filtering all the database showing any record, example 01/12/2021 until 06/12/2021 and it's not showing any record despite I have records between this dates, however something weird happens when I make this time window wider like 01/12/2021 until 31/12/2021 it shows all this records
    I hope anyone find something that I would be missing
    I highly appreciate support!!


    My code is this one


    'If Me.StartDatetxt <> "" And Me.EndDatetxt <> "" Then




    'Me.Requery
    'Me.Filter = "Fecha_Apertura >= #" & StartDatetxt & "# And Fecha_Apertura <= #" & EndDatetxt & "#"
    'Me.FilterOn = True


    'End If

    Thanks!!!

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Perhaps:
    'Me.Filter = "[Fecha_Apertura] >= #[StartDatetxt]# And [Fecha_Apertura] <= #[EndDatetxt]#"

    Why the Me.Requery ?
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Or maybe:

    Me.Filter = "[Fecha_Apertura] BETWEEN #[StartDatetxt]# AND #[EndDatetxt]#"
    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.

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,938
    I presume

    01/12/2021 until 06/12/2021

    is between 1st and 6th December

    However the filter will interpret this as between 12th Jan and 12th June because it uses the US date format. Note that if the date is say 31/12/2021 then it will be interpreted correctly as dd/mm/yyyy because there aren't 31 month in a year. So

    when I make this time window wider like 01/12/2021 until 31/12/2021 it shows all this records
    means between 12th Jan and 31st Dec. Which suggests you don't have any records for Jan-Nov.

    You need to reformat to the US date format of mm/dd/yyyy or the more generic yyyy-mm-dd

    "Fecha_Apertura >= #" & format(StartDatetxt,"yyyy-mm-dd) & "# And Fecha_Apertura <= #" & format(EndDatetxt,"yyyy-mm-dd) & "#"

    Final note - if
    Fecha_Apertura contains a time element (which may have been hidden because of formatting the field in the table) then any records for the 'To' day will not be returned since the 'To' date is considered to be midnight - so records for that date with a time element will be after that date.

  5. #5
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Might also look at International Dates in Access (by Allen Browne).... #2

  6. #6
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186
    Thanks to everybody in fact all were greats ideas and in this time the issue was as ajax said, my unbound fields are set as US date format and if I write into the fields as Latin date format (dd-mm-yyyy) is taking this instead of December 01, it takes Jan 12th

    Thanks for the good ideas!!!!

  7. #7
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186
    how can I correct this entry from the unbound fields? I mean I made the query as 12/01/2021 till 12/06/2021 (Dec 01th to Dec 06th) and it works as Ajax said, but my users enter data as Latin format (dd/mm/yyyy)

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,566
    Quote Originally Posted by charly.csh View Post
    how can I correct this entry from the unbound fields? I mean I made the query as 12/01/2021 till 12/06/2021 (Dec 01th to Dec 06th) and it works as Ajax said, but my users enter data as Latin format (dd/mm/yyyy)
    See post #4 ?
    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

  9. #9
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I use the "Function SQLDate" by Allen Browne (Post #5). I'm in the USA, but when dealing with international dates, I never have to worry when I use "Function SQLDate". Just another option......

  10. #10
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186
    Good Idea too!

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

Similar Threads

  1. Replies: 7
    Last Post: 02-03-2021, 08:08 AM
  2. Filter Report with Most Recent Dates
    By ahuffman24 in forum Access
    Replies: 13
    Last Post: 01-08-2020, 06:32 AM
  3. Replies: 3
    Last Post: 02-25-2016, 02:56 PM
  4. Filter overdue dates
    By jhallcb in forum Access
    Replies: 6
    Last Post: 03-10-2015, 10:56 AM
  5. How to filter dates using an apply filter code.
    By Jgreenfield in forum Reports
    Replies: 4
    Last Post: 11-15-2011, 01:38 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