Results 1 to 3 of 3
  1. #1
    Mattbro is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Posts
    100

    Query for Range to encompass given date

    Hello all,
    Annual leave-I am trying to create a query to show me who is off work on a given date-'DateX'.
    I have a table-tblLeave which has;
    'LeaveID' as the pk,
    StartDate-1st day of leave
    EndDate -last day of leave
    StaffID.
    I have tried querying where if I give a date, if said date falls within the StartDate and EndDate, the data will show. Of course, using quries such as
    Code:
     
    SELECT  *,
    DateX >= StartDate And DateX < EndDate AS Active
    FROM tblLeave;
    gives me a value for all leave events that start before the DateX, and all end dates that finish after DateX....which is just about all leave events on the calendar.


    Any ideas?
    Many thanks,
    Mattbro

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    The condition needs to be in a WHERE clause, i.e.
    Code:
    SELECT  *
    FROM tblLeave
    WHERE DateX Between StartDate And EndDate;
    (assuming that DateX, StartDate, and EndDate are all valid date fields).

  3. #3
    Mattbro is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Posts
    100
    Fantastic. Thanks JoeM

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

Similar Threads

  1. Graph date range from query
    By dhicks19 in forum Access
    Replies: 1
    Last Post: 06-29-2012, 12:26 AM
  2. Date Range Query
    By need_help12 in forum Queries
    Replies: 7
    Last Post: 04-25-2012, 01:38 PM
  3. Run query by date range
    By ARickert in forum Access
    Replies: 2
    Last Post: 06-23-2011, 10:54 AM
  4. Complicated Query needs some date range help
    By KevinMCB in forum Queries
    Replies: 1
    Last Post: 01-11-2011, 12:25 PM
  5. Date range query from form
    By Steve Barnes in forum Queries
    Replies: 2
    Last Post: 07-29-2010, 07:06 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