What's the best way to keep a user on a control...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • noclueforid
    New Member
    • May 2010
    • 24

    What's the best way to keep a user on a control...

    I want to add some data validation to a control, and keep the user there until the data is entered correctly. What I am trying to do is force a user to enter a correct date, based on another date field.

    Code:
    Private Sub Training_End_AfterUpdate()
    
    If [Training_End] > DateAdd("d", 1092, [Training_Start]) Then
     MsgBox "The Training End Date is greater than 156 weeks from the Training Start Date.", vbExclamation + vbOKOnly, "Error 101"
    End If
    End Sub
    What's the best way to do this?

    Thanks!
    Dave
  • slenish
    Contributor
    • Feb 2010
    • 283

    #2
    The best way I can think of is to keep what you have and just add in..

    Cancel = True

    right after your MsgBox before your End If so if they put in the wrond date it will keep the focus on the box till they put in the right date.

    Comment

    Working...