Results 1 to 4 of 4
  1. #1
    Wingnut74 is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2020
    Posts
    10

    Search between 2 dates using 2 textboxes

    Hi
    I have been creating a small Access database for my partners business and everything was going well until I tried to search services between two dates, everything works fine when I run the query but when I try and run from a form the first textbox (txtStartDate)will only accept the date in US format while the other textbox (txtEndDate) will only work in UK format (which is what I want). I have tried changing all the format settings, Cdate, I even copied the txtEndDate to see if it made any difference.

    txtStartDate will only work correctly when I change the date to US eg. 01/04/2020 needs to be 04/01/2020
    txtEndDate works fine with 30/04/2020, however when I try both dates in US format the txtEndDate changes back to UK format.

    I would be very grateful for any help you can give me.


    The only code relating to these textboxes is as follows:


    Code:
    Sub Search()
    Me.Refresh
    Dim strCriteria, task As String
    If IsNull(Me.txtStartDate) Or IsNull(Me.txtEndDate) Then
        MsgBox "please enter a Date Range", vbInformation, "Date Range Required"
        Me.txtStartDate.SetFocus
    Else
        strCriteria = "([ServiceDate] >= #" & Me.txtStartDate & "# AND [ServiceDate] <= #" & Me.txtEndDate & "#)"
        task = "SELECT * from qryServicesSearch WHERE (" & strCriteria & ") ORDER by [ServiceDate]"
        DoCmd.ApplyFilter task
        
    End If
           
    End Sub
    

  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
    The following link my be of interest: http://allenbrowne.com/ser-36.html#Interface
    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
    Wingnut74 is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2020
    Posts
    10
    Hi Bob
    Followed the link and my problem was solved.

    Many thanks for your guidance.

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Glad you got it sorted
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

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

Similar Threads

  1. Search field for Dates
    By Topflite66 in forum Forms
    Replies: 4
    Last Post: 04-10-2020, 08:49 AM
  2. How to search for subsequent dates in form
    By Beeblebrox in forum Programming
    Replies: 13
    Last Post: 04-28-2016, 10:14 AM
  3. Replies: 3
    Last Post: 03-27-2013, 08:27 AM
  4. Search Query - Between Dates
    By AndreasPanayiotou in forum Queries
    Replies: 1
    Last Post: 09-10-2012, 07:06 AM
  5. Search for specific dates
    By natalia in forum Queries
    Replies: 2
    Last Post: 09-27-2010, 03:15 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