Results 1 to 4 of 4

Thread: Date Checker

  1. #1
    2 Star Lounger
    Join Date
    Mar 2002
    Posts
    132
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What is the simpliest way to check that the date entered is greater than the already stored. For example

    Private Sub Last_Reviewed_BeforeUpdate(Cancel As Integer)

    If Me.LastReviewedDate < Me.LastReviewedDate Then

    MsgBox 'the date entered must be later than the current date
    Cancel = True ' caused the changes to not be saved

    End If

    End Sub

    Just looking for the best way.

  2. #2
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts
    Assuming that the data behind the control is indeed stored in date format, that should work. However you should probably use the .Value in one of those, as I believe your statement will never be true. I would code it as

    If Me.LastReviewedDate < Date() Then

    That says you can't leave the control unless it is the current date. However if focus never moves to that control, then the date won't get checked. For that reason, if you want to force someone to enter a date before they leave the form, you may want to use one of the other Form events such as Current or LostFocus.
    Wendell

  3. #3
    2 Star Lounger
    Join Date
    Mar 2002
    Posts
    132
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How do I code the date from the form (currently being entered) vs. the date from the table (stored date to be overwritten)?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    The stored value is available in the OldValue property of the control:

    Code:
    Private Sub Last_Reviewed_BeforeUpdate(Cancel As Integer)
      If Me.LastReviewedDate < Me.LastReviewedDate.OldValue Then
    	MsgBox 'the date entered must be later than the current date
    	Cancel = True ' caused the changes to not be saved
      End If
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •