Results 1 to 2 of 2
  1. #1
    AndreasPanayiotou is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    21

    Search Query - Between Dates

    Hello to all ,
    From the morning until now i am trying to get done a search query that takes four parameters
    The employee name , start and end date of the annual leave as also the annual leave type.
    The query basicly is working but it does not take the real BETWEEN values between start and end date.
    As i realised when i search for a start end end date i want the search to get results in any correlated dates .
    Here is my query:
    SELECT Main.MainID, Employee.EmployeeName, Main.StartDate, Main.EndDate, LeaveType.LeaveType
    FROM Season INNER JOIN (LeaveType INNER JOIN (Employee INNER JOIN Main ON Employee.EmployeeID = Main.EmployeeID) ON LeaveType.LeaveID = Main.LeaveID) ON Season.SeasonID = Main.SeasonID
    WHERE (Employee.EmployeeName Like Forms!SearchForm!EmployeName & "*" or Forms!SearchForm!EmployeName Is Null)
    And (LeaveType.LeaveType Like Forms!SearchForm!LeaveType & "*" or Forms!SearchForm!LeaveType Is Null)
    BETWEEN (Main.StartDate Like Forms!SearchForm!StartDate & "*" or Forms!SearchForm!StartDate Is Null)
    And (Main.EndDate Like Forms!SearchForm!EndDate & "*" or Forms!SearchForm!EndDate Is Null);

    The join was mannualy done by access but the type of query was by me manualy typed
    The issue here is the start and end date, the between is not actually working as when i search for example start date is 24/02/2012 and end date 31/08/2012 i am not getting between results , i will get the start date result as also any date that equals the end date.
    My first thought is about the join type but i have changed all the joins type and i am anot getting any different results.
    My second is about the between statement , if is correct statement that i am doing.
    Any thoughts ,recommendation and help would be welcome.
    Thank you

  2. #2
    AndreasPanayiotou is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    21
    After of several try’s I have found the right syntax , it was easier than I thought
    Here is the syntax:

    SELECT Main.MainID, Employee.EmployeeName, Main.StartDate, Main.EndDate, LeaveType.LeaveType
    FROM Season INNER JOIN (LeaveType INNER JOIN (Employee INNER JOIN Main ON Employee.EmployeeID = Main.EmployeeID) ON LeaveType.LeaveID = Main.LeaveID) ON Season.SeasonID = Main.SeasonID
    WHERE ([Employee.EmployeeName] Like Forms!SearchForm!EmployeName & "*" or Forms!SearchForm!EmployeName Is Null)
    And ([LeaveType.LeaveType] Like Forms!SearchForm!LeaveType & "*" or Forms!SearchForm!LeaveType Is Null)
    AND ([Main.StartDate]>=Forms!SearchForm!StartDate or Forms!SearchForm!StartDate Is Null)
    And ([Main.EndDate]<=Forms!SearchForm!EndDate or Forms!SearchForm!EndDate Is Null);

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

Similar Threads

  1. IIf Query with dates
    By DelbyJones in forum Access
    Replies: 2
    Last Post: 08-16-2012, 02:33 PM
  2. Query input dates for range of dates in two fields
    By kagoodwin13 in forum Queries
    Replies: 3
    Last Post: 02-13-2012, 04:25 PM
  3. Run Query by dates
    By BorisGomel in forum Access
    Replies: 3
    Last Post: 07-21-2011, 03:54 PM
  4. Mixed dates - show only complete dates?
    By weeblesue in forum Queries
    Replies: 3
    Last Post: 10-27-2010, 02:15 PM
  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