Results 1 to 5 of 5
  1. #1
    C Muth is offline Novice
    Windows 10 Access 2007
    Join Date
    Jun 2019
    Posts
    13

    Query Prompting User to Enter Date Range

    I am starting with a linked OBDC table with a date formatted as Short Text. Example: 20191112 07:22:32.54


    Q1 breaks down and rebuilds the the date and time

    SELECT log.DATE_TIME, Mid([DATE_TIME],5,2) AS TMONTH, Mid([DATE_TIME],7,2) AS TDAY, Left([DATE_TIME],4) AS TYEAR, CDate([TMonth] & "/" & [TDay] & "/" & [TYear]) AS TDATE, Mid([DATE_TIME],10,5) AS TTIME, [TDate] & " " & [TTime] AS TDATETIME
    FROM log

    My goal for Q2 is to have the user prompted to enter a range of dates (which have have done successfully in other access databases with no issue)

    The Criteria I entered is: >="#" And [Enter Start Date] And "#" And <="#" And [Enter End Date] And "#"


    The query runs, however returns no results.
    When I hardcode a date range in the Criteria formatted as follows: >=#11/12/2019# And <=#11/14/2019#, it returns the desired results.

    Question: what can I do to fix the Criteria to allow the user to enter a range of dates and receive the desired results?

    Any guidance would be appreciated.

  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,963
    This is in a query object - don't need concatenation nor # characters with input prompt. Try BETWEEN AND instead of >=, <=

    BETWEEN [Enter Start Date] AND [Enter End Date]

    I never use dynamic parameter popup input because cannot validate user entry. Better to reference controls on form for user input.


    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
    C Muth is offline Novice
    Windows 10 Access 2007
    Join Date
    Jun 2019
    Posts
    13
    thanks. when I use "BETWEEN" Q2 returns Nov 12, Nov 13 and Nov 14 data, however for years 2016, 2017, 2018, + 2019. Hence the use of the #. The unexpected results were the subject of another thread I started. Any thoughts appreciated.

    Query on Date (M/D/YY) field seems to be ignoring YY in Access

    Noted re: user entry via a form. For now only a couple users, will enhance if and as we roll out to additional users.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,963
    Sorry, I am using only Access tables so I am not 'rebuilding' date. So I just tested that and I see the behavior you describe. Even with the symbol operators, not just BETWEEN AND.

    Aside from not using dynamic parameters in query, don't have a solution.
    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.

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,991
    In the end changing the datatype from short text to datetime would solve a lot of problems and save you a lot of time
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

Similar Threads

  1. Replies: 4
    Last Post: 05-23-2019, 07:20 AM
  2. Replies: 17
    Last Post: 07-31-2018, 01:23 PM
  3. Replies: 1
    Last Post: 10-09-2015, 09:29 AM
  4. Prompting for user input in query
    By sherrygroves in forum Access
    Replies: 7
    Last Post: 08-31-2014, 09:32 PM
  5. Prompt User for Date Range when running QUERY
    By taimysho0 in forum Programming
    Replies: 3
    Last Post: 01-30-2012, 11:49 AM

Tags for this Thread

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