Share via

check-in date & check-out date (hotel)

Anonymous
2012-10-04T01:46:09+00:00

Hi,

trying to create a form that can total up how many nights staying in the hotel, for example:

  1. if check-in 10/1/2012, check-out 10/3/2012, then is 2 nights, how to make it auto calculate for 2 nights?
  2. if all guests must book the rooms for at least 2 nights, how to make sure it can not be book for 1 night?
Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. Anonymous
    2012-10-04T01:55:37+00:00
    1. Take a look at the VBA help for the DateDiff() function: open the VBA editor by typing Ctrl-G or Alt-F11, press F1 for Help, and search for DateDiff. It'll do what you're asking.
    2. Use some VBA code in the BeforeUpdate() event of the form in which you're entering the data (you must use a Form, tables don't let you do this), and use DateDiff to calculate the stay. If it's invalid  - less than 2 - use MsgBos to warn the user and set Cancel to True to cancel the update.
    1 person found this answer helpful.
    0 comments No comments
  2. ScottGem 68,810 Reputation points Volunteer Moderator
    2012-10-04T11:47:50+00:00

    i'm still trying to figure how to be sure must book at least 2 nights, any way to do this?

    You can set a validation rule on the Checkout_Date For 

    DateDiff("d",Checkin_Date,Checkout_date)>=2

    However, what I would do is default the Checkout_Date. In the After Update event of the Check_inDate control I would put:

    Me.Checkout_Date=DateAdd("d",2,Me.Checkin_Date)

    Then in the After Update event of Checkout_date control I would use code leik:

    If Me.Checkout_Date<Me.CheckOut_date.oldValue Then

    MsgBox "Checkout date has to cover 2 nights!"

    Me.checkout_date=Me.checkout_date.OldValue

    End If

    0 comments No comments
  3. Anonymous
    2012-10-04T10:49:37+00:00

    I tried:

    =IIf([Checkin_Date]=[Checkout_Date],1,DateDiff("d",[Checkin_Date],[Checkout_Date]))

    this works great

    i'm still trying to figure how to be sure must book at least 2 nights, any way to do this?

    0 comments No comments