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

    Filter between two dates from unbound fields .... Wrong code...

    Hello everyone

    I'm trying to filter a database between two dates in a form, the issue I have is that the fields originally were textboxes (unbound) with 'input mask' as :00/00/0000;0;_

    And of course in the format of those were added 'Short Date'

    The field originally to be filtered was called 'Date' from table (I know MS Access has that name reserved for itself) for that reason I changed the name in the form to Datetxt in the properties

    With my code I inserted....

    Private Sub Filtercmd_Click()

    Me.Requery
    Me.Filter = "Datetxt >= "& "#" & StartDatetxt & "#" And "Datetxt <="& "#" & EndDatetxt & "#"


    Me.FilterOn = True

    End Sub

    It shows an error, what could be wrong?

  2. #2
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    You have the syntax of the filter statement wrong - the "And" must be in quotes as well. Try this:

    Me.Filter = "Datetxt >= #" & StartDatetxt & "# And Datetxt <= #" & EndDatetxt & "#"

    John

  3. #3
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186
    It changed that to your code and it shows an input box asking me ENTER PARAMETER VALUE "Datetxt"

    Do you know why?

  4. #4
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    It is probably because there is no field called "Datetxt" in the table or query that is the recordsource for the form. The filter must refer to the RecordSource field names, not the names of the form Controls. If you (correctly) don't want to use "Date" as a field name, you have to change it in the table as well as on the form.

  5. #5
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186
    You were right that was the problem!!!
    thank you very much!!!

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

Similar Threads

  1. Query input dates for range of dates in two fields
    By kagoodwin13 in forum Queries
    Replies: 3
    Last Post: 02-13-2012, 04:25 PM
  2. How to filter dates using an apply filter code.
    By Jgreenfield in forum Reports
    Replies: 4
    Last Post: 11-15-2011, 01:38 PM
  3. What's wrong with my code?
    By Dalagrath in forum Forms
    Replies: 11
    Last Post: 05-18-2011, 04:34 PM
  4. What's wrong with this filter?
    By jgelpi16 in forum Queries
    Replies: 4
    Last Post: 02-21-2011, 12:58 PM
  5. What is wrong with this code?
    By nkenney in forum Forms
    Replies: 2
    Last Post: 11-16-2009, 03:04 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