Results 1 to 6 of 6
  1. #1
    Davism4 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2021
    Posts
    6

    Time search Query

    Hi , hoping someone can help me with this!




    I have the following query criteria which checks for dates between 2 date textboxes, or returns everything if dates are not entered.

    >=[Forms]![RMS HISTORY]![FromDate] And <=[Forms]![RMS HISTORY]![ToDate]+1 Or is null


    This works great, but I also want to add time boxes to check be able to check between 2 times.
    There is a Time field in the table, so I thought it would be easy to just repeat the above but point to Time field and Time textboxes:

    >=[Forms]![RMS HISTORY]![FromTime] And <=[Forms]![RMS HISTORY]![ToTime]


    But it seems Access can only handle one of these statements at a time, and it doesn't work.
    How do I work around it?
    What is the best method to set this up?

    Best regards

    Mark

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    'doesn't work' doesn't help use to help you - you get an error? wrong result? something else?

    It may be obvious to you but not us - provide some example data, example criteria and the result required

    As a general comment usually better to combine your date and time fields and form fields and compare the result, but you haven't said what you expect as a result so maybe not

    Are you sure the time fields only contain time (i.e. the date element is 0)?

    And what are the users actually entering on the form

  3. #3
    Cottonshirt is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Feb 2018
    Posts
    116
    I take it this is a WHERE statement ?

    if so, try this

    Code:
    WHERE (((([fieldname])>=[Forms]![RMS HISTORY]![FromTime]) And (([fieldname])<=[Forms]![RMS HISTORY]![ToTime])))

    good luck with your project,



    Cottonshirt

  4. #4
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    think the OP's code is based on what they see in the query builder, not in the sql. Sql view would show the code as you have it.

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    You could try adding the date and time controls?
    They are numbers after all?
    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

  6. #6
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    think the OP has gone away

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

Similar Threads

  1. Replies: 5
    Last Post: 08-29-2019, 04:25 PM
  2. Replies: 10
    Last Post: 07-07-2017, 05:11 PM
  3. Run time error 2465 on search form
    By Jims Chan in forum Forms
    Replies: 5
    Last Post: 01-05-2017, 04:00 AM
  4. Replies: 6
    Last Post: 04-19-2016, 03:58 PM
  5. Date/Time Search Midnight Issue
    By Coffee in forum Queries
    Replies: 5
    Last Post: 07-26-2011, 01:54 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