Results 1 to 7 of 7
  1. #1
    Akchayan is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Aug 2022
    Posts
    102

    Filter between 2 data

    Hello all,




    I have a form that is connected to a table. I have the column "Invoice date" there.
    In the form I have this input:
    Click image for larger version. 

Name:	Screenshot 2023-01-18 184033.png 
Views:	25 
Size:	7.2 KB 
ID:	49509
    txt1 is the first date
    txt2 is the second date


    The filter should be between txt1 and txt2. So it should be filtered in the column "Invoice date".


    It should be filtered as soon as I click on the "filtern" button.


    How do I do that?
    Attached Thumbnails Attached Thumbnails Screenshot 2023-01-18 184033.png  

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    Lookup setting a filter on a form.
    Basically, define the filter, then set filter=on
    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

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    me.filter = "[fieldname] between '" & me.txt1 & "' and '" & txt2 & "'"
    me.filterON = true

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    A small tweak to ranman's suggestion as you mention your filtering on a date field:
    Code:
    Me.Filter = "[fieldname] between #" & me.txt1 & "# and #" & txt2 & "#"
    Me.FilterOn = True
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    Akchayan is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Aug 2022
    Posts
    102
    Quote Originally Posted by Gicu View Post
    A small tweak to ranman's suggestion as you mention your filtering on a date field:
    Code:
    Me.Filter = "[fieldname] between #" & me.txt1 & "# and #" & txt2 & "#"
    Me.FilterOn = True
    Cheers,
    I copied the code but i get a error at "Me.FilterOn = True" :
    Click image for larger version. 

Name:	Screenshot 2023-01-19 144835.png 
Views:	12 
Size:	5.6 KB 
ID:	49517
    The error code says:
    Runtime error 3076


    Syntax error in date in criteria expression.

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    Debug.print Me.filter and post back here.

    Do yourself a favour, give your controls some meaningful names , textxx is not going to mean anything to anyone in a few months.
    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

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793
    There is no guarantee that the date is date data type?
    @Akchayan, are the dates left or right justified in your table, or can you say with certainty what data type they are by looking at table design if need be?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Filter out data in a query
    By CaliburBlade138 in forum Queries
    Replies: 3
    Last Post: 03-18-2022, 11:23 AM
  2. Using WHERE to filter data
    By kloun04 in forum Queries
    Replies: 9
    Last Post: 11-05-2018, 04:23 PM
  3. Use checkbox to filter data
    By acm007 in forum Access
    Replies: 5
    Last Post: 06-15-2018, 07:29 AM
  4. Replies: 7
    Last Post: 09-08-2016, 05:06 PM
  5. Replies: 1
    Last Post: 03-22-2015, 02:21 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