Results 1 to 6 of 6
  1. #1
    techwonder is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    Dec 2014
    Posts
    6

    Raise an error when dates overlap


    Have a database with 3 different Hotels, 3 different room numbers a DateFrom and DateTo.

    Need to create a BEFORE CHANGE trigger that will not let me enter booking dates within a DATEFROM and DATETO range existing in other fields.

    Can't put actual dates in the Macro since not a constant. Need it to 'read' all the parameters first.

    So for example Hotel 1, room 143 has dates 6/12/14 - 6/18/14 booked. Change should stop me when I enter 6/13/14 on any row that has the same HotelNumber and Room Number

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Use DLookup like:

    If Not IsNull(DLookup("ID", "Bookings", "#" & Me.tbxDateFrom & "# BETWEEN [DateFrom] AND [DateTo] AND HotelID=" & Me.tbxHotelID & " AND RoomID=" & Me.tbxRoomID)) OR Not IsNull(DLookup("ID", "Bookings", "#" & Me.tbxDateTo & "# BETWEEN [DateFrom] AND [DateTo] AND HotelID=" & Me.tbxHotelID & " AND RoomID=" & Me.tbxRoomID)) Then
    'do this
    End If

    Or open a recordset object using that same filter criteria. If the recordset is empty then there is no conflict.
    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
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I think it's more complicated than that:

    http://www.baldyweb.com/OverLap.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    techwonder is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    Dec 2014
    Posts
    6
    Quote Originally Posted by June7 View Post
    Use DLookup like:

    If Not IsNull(DLookup("ID", "Bookings", "#" & Me.tbxDateFrom & "# BETWEEN [DateFrom] AND [DateTo] AND HotelID=" & Me.tbxHotelID & " AND RoomID=" & Me.tbxRoomID)) OR Not IsNull(DLookup("ID", "Bookings", "#" & Me.tbxDateTo & "# BETWEEN [DateFrom] AND [DateTo] AND HotelID=" & Me.tbxHotelID & " AND RoomID=" & Me.tbxRoomID)) Then
    'do this
    End If

    Or open a recordset object using that same filter criteria. If the recordset is empty then there is no conflict.
    I think this is the right idea but I am not certain what to do with the Me.tbx part? This class is so basic that is all greek to me.

  5. #5
    techwonder is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    Dec 2014
    Posts
    6
    Quote Originally Posted by pbaldy View Post
    I think it's more complicated than that:

    http://www.baldyweb.com/OverLap.htm
    Haha.. yes I read this before I posted. I appreciate it. It helps lay it out in terms of explanation but the syntax of my specific problem is what is confusing me. In other words the whole table could be blank except for one date range which would be the only thing being read. Does your solution work with that?

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Well, the goal is to find out if anything conflicts with what you have on the form, so that query should work (adding the other criteria of course).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. #ERROR when subtracting dates
    By nlkehl in forum Queries
    Replies: 7
    Last Post: 08-26-2014, 08:24 AM
  2. Looking for overlap in dates between two records
    By kagoodwin13 in forum Queries
    Replies: 4
    Last Post: 03-09-2012, 12:37 PM
  3. Help with "overlap" query
    By Darrick in forum Queries
    Replies: 3
    Last Post: 07-12-2011, 12:23 PM
  4. Filtering Dates Error!
    By emilyrogers in forum Forms
    Replies: 3
    Last Post: 02-15-2011, 03:00 AM
  5. Replies: 0
    Last Post: 09-25-2006, 07:14 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