Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    ijaz8883 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    103

    Search Between Date in form

    Hi Experts
    I am facing a problem in a search form. The Search is working perfect but there is a problem Its searching the date as mm/dd/yyyy as today date "05/09/2022" however I want to search as dd/mm/yyyy. My Computer Date and Database Date is also set as dd/mm/yyyy as today date "09/05/2022"

    Const conJetDate = "dd/MM/yyyy"

    varWhere = Null
    it is also entered in codes


    I am using the code:
    Private Sub txtdatefrom_AfterUpdate()
    Me.RecordSource = "SELECT * FROM Complete_Criminal " & BuildFilter
    Me.Requery
    End Sub


    If Me.txtdatefrom > "" Then
    varWhere = varWhere & "([decision_date] >= " & Format(Me.txtdatefrom, conJetDate) & ") AND "
    End If




    Its working as mm/dd/yyyy
    But when I search as:

    If Me.txtdatefrom > "" Then
    varWhere = varWhere & "[decision_date] like '*" & Me.txtdatefrom & "*' AND "
    End If
    It works perfect as I desired but its search the exact date but I want to search date from and date to, How can I add grater than less than with like as like => , like =<.
    whenever I tried to write the dual statements its give errors.
    Let me know what to do?


    Click image for larger version. 

Name:	Structure.jpg 
Views:	44 
Size:	25.7 KB 
ID:	47767

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Wildcards don't work well with number and date/time data, they are intended for text.

    "[DecisionDate] >= #" & Me.txtDateFrom & "# AND [DecisionDate]<=#" & Me.txtDateTo & "#"

    Or

    "[DecisionDate] BETWEEN #" & Me.txtDateFrom & "# AND #" & Me.txtDateTo & "#"
    Last edited by June7; 05-09-2022 at 09:57 PM.
    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.

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    No need to requery either, if you just set recordsource.
    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

  4. #4
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Also note that dates must be delimited with octothorpes #
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  5. #5
    ijaz8883 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    103
    Quote Originally Posted by June7 View Post
    Wildcards don't work well with number and date/time data, they are intended for text.

    [DecisionDate] >= #" & Me.txtDateFrom & "# AND [DecisionDate]<=#" & Me.txtDateTo & "#"

    Or

    [DecisionDate] BETWEEN #" & Me.txtDateFrom & "# AND #" & Me.txtDateTo & "#"
    Sorry to say dear I dont understand where to put this code because I am biginner.
    I am attaching my DB Sample and lets check that when I search date in like command its work perfect but when I search dates with other => commands its not showing the dates as dd/mm/yyyy.

    Let me know where to put code that its work perfect as I desired.
    Note: I have also other multiple search fields like text search with these date fiels that are working but I have deleted so that you feel relex to work with the above said problem.

    Record Check.zip

  6. #6
    ijaz8883 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    103
    Thanks I shall take care for the next. I just have copied the code from other DB already available on net.

  7. #7
    ijaz8883 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    103
    Quote Originally Posted by moke123 View Post
    Also note that dates must be delimited with octothorpes #
    octothorpes # not working in my db lets check I have attached my DB Dample

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    I provided you two options for date criteria to use in your code to replace the failing string you posted.

    However, your dates are international structure so review http://allenbrowne.com/ser-36.html and http://allenbrowne.com/ser-62code.html
    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.

  9. #9
    ijaz8883 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    103
    Quote Originally Posted by June7 View Post
    I provided you two options for date criteria to use in your code to replace the failing string you posted.

    However, your dates are international structure so review http://allenbrowne.com/ser-36.html and http://allenbrowne.com/ser-62code.html
    I have tried this one but its not working. If you have time please check my DB and make necessary correction. Thanks

  10. #10
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    From Allen Browne:
    In VBA code, delimit dates with the "#" symbol. Regardless or your regional settings, Access expects these literal dates to be in the American format, e.g. #12/31/1999#.
    you are using
    Code:
    Const conJetDate = "\#dd\/mm\/yyyy\#"
    Allen's code is
    Code:
    Const conJetDate = "\#mm\/dd\/yyyy\#"


    I used the below which appeared to work fine
    Code:
    Me.RecordSource = "SELECT * FROM tblCriminal where [decision_date] between #" & Me.txtdatefrom & "#  and # " & Me.txtDateTo & "#"
    you may want to use a filter.
    You can format a field in your query to display the date as dd/mm/yyyy
    Code:
    Dim strFilter As String
    strFilter = "[decision_date] between #" & Me.txtdatefrom & "#  and # " & Me.txtDateTo & "#"
    Me.Filter = strFilter
    Me.FilterOn = True
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  11. #11
    ijaz8883 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    103
    Quote Originally Posted by moke123 View Post
    From Allen Browne:


    you are using
    Code:
    Const conJetDate = "\#dd\/mm\/yyyy\#"
    Allen's code is
    Code:
    Const conJetDate = "\#mm\/dd\/yyyy\#"


    I used the below which appeared to work fine
    Code:
    Me.RecordSource = "SELECT * FROM tblCriminal where [decision_date] between #" & Me.txtdatefrom & "#  and # " & Me.txtDateTo & "#"
    you may want to use a filter.
    You can format a field in your query to display the date as dd/mm/yyyy
    Code:
    Dim strFilter As String
    strFilter = "[decision_date] between #" & Me.txtdatefrom & "#  and # " & Me.txtDateTo & "#"
    Me.Filter = strFilter
    Me.FilterOn = True
    Sorry to Say its not worked.
    However, you suddenly give me another way to think and I got it by coding manually. I don't know I do good or bad but I have done my work. may be in future its make problem, if so I shall consult you again in this forum.
    I just Delete the Code: Const conJetDate = "\#dd\/mm\/yyyy\#" and maunally entered in command line
    "
    varWhere = varWhere & "([decision_date] >= " & Format(Me.txtdatefrom, dd - mm - yyyy) & ") AND " " and its (done its (dd - mm - yyyy) worked for me as I desired.
    However thanks to all for giving me new thaught . Glade to see you all.


    This is the best forum to discuss Access problems.

  12. #12
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    No, that is not going to work.
    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

  13. #13
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Access stores dates as the number of days since 12/31/1899. So todays date is stored as 44692.
    Jet/Ace uses the U.S. date format regardless of what format your computer is set to in your regional settings.
    Therefore to get accurate results you need to convert your international dates to a format that jet/ace uses.
    Code:
    Const conJetDate = "\#mm\/dd\/yyyy\#"
    Format(Me.txtdatefrom, conJetDate)
    Added bonus to the above is that it delimits your dates with octothorpes so access knows it is a date datatype.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  14. #14
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    To avoid any confusion, if you format your dates #yyyy-mm-dd# access always get it's conversions right, and if you are debugging it's much easier to see the exact date being passed around, without wondering what format is being used or displayed.

    This works everywhere no matter what your regional settings are.
    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 ↓↓

  15. #15
    ijaz8883 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    103
    Quote Originally Posted by Minty View Post
    To avoid any confusion, if you format your dates #yyyy-mm-dd# access always get it's conversions right, and if you are debugging it's much easier to see the exact date being passed around, without wondering what format is being used or displayed.

    This works everywhere no matter what your regional settings are.
    Sorry but my requirement was alongwith Regional Setting so I have to do this because its familiar to us. Thanks

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 15
    Last Post: 07-22-2017, 05:15 PM
  2. Search form with date
    By Delta729 in forum Forms
    Replies: 4
    Last Post: 07-14-2015, 04:56 PM
  3. Form to search for data by date range
    By andyt_2005 in forum Forms
    Replies: 3
    Last Post: 08-02-2014, 11:32 AM
  4. Replies: 4
    Last Post: 05-26-2012, 09:29 AM
  5. Search form with a date range
    By mantro174 in forum Forms
    Replies: 1
    Last Post: 02-11-2009, 10:45 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