Results 1 to 12 of 12
  1. #1
    Troop is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    15

    Validation Rules Help

    In my booking form, that the number in putted for the nights that they want a service for doesn't go over the number of nights stayed. EG A man staying for 2 nights can't have a service of TV for 35 days as he is not staying for 35 nights. How do I do this?

    https://www.dropbox.com/s/waqt49e487...0Hotel.accdb?m

  2. #2
    Troop is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    15
    I tried making the validation rule here it is

    [Checkout]-[Arrival]<=[Internet Required (Nights)]

    But for some reason it says 'Invalid SQL syntax, cannot use multiple columns in a column level CHECK constraint.'
    How do I rectify this?

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Where did you try that - in textbox ValidationRule property, in a query, in macro or VBA code?
    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.

  4. #4
    Troop is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    15
    Quote Originally Posted by June7 View Post
    Where did you try that - in textbox ValidationRule property, in a query, in macro or VBA code?
    I did this in the Validation Rule field.

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Try:

    Is Null Or <=[Checkout]-[Arrival]
    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.

  6. #6
    Troop is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    15
    Doesn't work, I tried it. Comes up with the same error message. Maybe something to do with the chekout minus the arrival?

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    I tested it in textbox ValidationRule property on form and it works for me, no error message.
    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.

  8. #8
    t. hagan is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    7
    The validation rule needs to be limited to a single field. I can see a couple of ways around this constraint.
    First you could base your form on a query and use a calculated field to determine the length of the stay. (This is something that you are probably doing already. Otherwise, you could never calculate charges.) If you press the build button in a blank column, you can place the following code there:
    LengthOfVisitateDiff("d", [Arrival], [Checkout])
    That creates the calculated field.
    Then you go to your form to create a validation rule that is based on that result, i.e. "<=[LengthOfVisit])
    If you went to VBA, you could construct a message that displays when the days of internet service exceed the length of the stay, something like:
    n = DateDiff("d", [Arrival], [Checkout])
    If n > [Days of Internet Service] Then
    msgbox "The days of internet service exceeds the length of the stay"
    End IF
    Good luck.

    Tim Hagan, http://www.peachtek.net

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    A calculated field is an option but I did test the calculation in the ValidationRule and it worked. It seemed a bit slow to respond but it did work.
    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.

  10. #10
    Troop is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    15
    Quote Originally Posted by June7 View Post
    I tested it in textbox ValidationRule property on form and it works for me, no error message.
    My mistake it comes up with the error 'Syntax error missing operator in table validation expression'

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Are you doing this in the table or on form? I did it on form.
    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.

  12. #12
    Troop is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    15
    Ah I was doing it on the table, slap me in the face. Sorry about that. Works so woop! Ty a lot.

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

Similar Threads

  1. Field rules/validation rules
    By sk88 in forum Access
    Replies: 14
    Last Post: 02-26-2012, 01:03 PM
  2. troubles with validation rules
    By focosi in forum Access
    Replies: 4
    Last Post: 08-02-2011, 10:46 AM
  3. Question about Validation Rules
    By WilsonsW in forum Access
    Replies: 1
    Last Post: 04-18-2011, 05:06 PM
  4. Validation Rules
    By esglover in forum Database Design
    Replies: 1
    Last Post: 07-23-2010, 08:02 PM
  5. Validation rules question
    By cps6568 in forum Access
    Replies: 3
    Last Post: 01-12-2010, 02:01 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