Results 1 to 4 of 4
  1. #1
    pjstrat00 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jun 2014
    Posts
    5

    Time Validation - Before Update Events

    Hi there,(access newbie here)

    I am trying to make a rule where the end time cannot be less than the start time. I've tried creating a validation rule in the table and have also tried the code in a before update event. I have the data type set to date time and the field names are "MondayStart" and "MondayEnd"



    Private Sub MondayStart_BeforeUpdate(Cancel As Integer)
    If Me.MondayStart>Me.MondayEnd then
    Msgbox "The end date must not come before the Start Date"
    Cancel=True ' caused the changes to not be saved
    End If


    End Sub

    I reviewed the closest previous post on this, but it recommends a before update event.

    I've tried creating the validation rule in the table, the form, and in the field in design view.

    Any ideas or links to where I can get this figured out?

    Thanks!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    You said time, but your MsgBox says date so I presume you meant date. What happens when you run the code?

    Try:

    If CDate(Nz(Me.MondayStart,"1/1/1900")) > CDate(Nz(Me.MondayEnd,"12/31/2900")) Then
    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
    pjstrat00 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jun 2014
    Posts
    5
    Quote Originally Posted by June7 View Post
    You said time, but your MsgBox says date so I presume you meant date. What happens when you run the code?

    Try:

    If CDate(Nz(Me.MondayStart,"1/1/1900")) > CDate(Nz(Me.MondayEnd,"12/31/2900")) Then
    I get a compile error: End if without block if. (I actually did mean time, my apologies)

    However, If I removed the End If, nothing seems to stop me from entering an end time earlier than my start time.

    I will try your suggestion, thank you!

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    If ... Then
    ...
    End If

    is proper syntax. Removing the End If should cause error.
    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.

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

Similar Threads

  1. Cannot set validation rule on Date/Time type
    By intheflesh77 in forum Access
    Replies: 2
    Last Post: 10-12-2013, 08:57 AM
  2. Replies: 1
    Last Post: 05-29-2013, 04:01 PM
  3. Replies: 3
    Last Post: 05-23-2013, 05:30 PM
  4. Validation rule for time
    By jle0003 in forum Access
    Replies: 3
    Last Post: 05-22-2012, 02:45 PM
  5. Time and Date Validation
    By KEVWB in forum Access
    Replies: 1
    Last Post: 03-06-2011, 08:31 AM

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