Date Validation Rule

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Betibox
    New Member
    • Apr 2008
    • 1

    Date Validation Rule

    Could somebody advise please ?:( I've got 2 dates in my Booking table StartHire and EndHire I wont the use Not to be able to input in the EndHire column date which is = or<than StartHire. Any clues would be appreciated.
    Thanks in advance.
    B
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    You should always have your data input into the table done thru a form, and in the code module of the form:

    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
     If Me.EndDate <= Me.StartDate Then
       MsgBox "End Date Must Occur After Start Date!"
       Cancel = True
       Me.EndDate.SetFocus
     End If
    End Sub
    Welcome to bytes!

    Linq ;0)>

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32656

      #3
      If you want to specify how two (or more) fields within a table relate to each other you can open the Properties window of a table in Design mode and specify your rule in the Validation Rule property there.

      In your case I suspect that you'd want :
      Code:
      [StartHire]<[EndHire]
      The Validation Text property can be used to specify an error message if you're not happy with the default one being used.

      Comment

      Working...