Results 1 to 7 of 7

Thread: Date Validation

  1. #1
    Join Date
    Sep 2003
    Location
    Raleigh, NC
    Posts
    183

    Unanswered: Date Validation

    I have two date fields that i want to do validation check.

    Date2 has to be >= to Date1

    I have wrote the following code which gives me msg whenever there is wrong date but it still allow me to bypass the field

    Me.Date1.SetFocus
    If Me.Date2.Text < Me.Date1 Then
    errMsg = errMsg & "Date2 must be after Date1" & vbCrLf
    End If

    Any Suggestion on what i'm doing wrong here ?
    Skharva

  2. #2
    Join Date
    Nov 2003
    Posts
    267
    Use the LostFocus Event to check the textbox when you remove the focus from the object.

    S-

  3. #3
    Join Date
    Sep 2003
    Location
    Raleigh, NC
    Posts
    183
    Originally posted by sbaxter
    Use the LostFocus Event to check the textbox when you remove the focus from the object.

    S-
    I try that and does give me a msg when i enter invalid date. But after the msg box it still let me go to the next field of the form. So basically if i input wrong date then msg box will pop up telling me that i input wrong date then it will go to next field.

    Private Sub txtExpDelivDate_LostFocus()
    Me.txtExpDelivDate.SetFocus
    If Me.txtExpDelivDate.Text < Me.txtDOB Then
    MsgBox "Exp.Deliv.Date must be after Date of Birth" & vbCrLf
    Me.lblDelivDateNull.Visible = True
    Else
    Me.lblDelivDateNull.Visible = False
    End If
    End Sub
    Skharva

  4. #4
    Join Date
    Mar 2004
    Location
    Greenville, SC
    Posts
    271

    Smile I use this

    I have used this after my message to take me back to the contol I want to enter the correct data.

    DoCmd.GoToControl "ContolsName"




    Surf
    Gotta to do some code

  5. #5
    Join Date
    Sep 2003
    Location
    Raleigh, NC
    Posts
    183

    Re: I use this

    Originally posted by surfacesys
    I have used this after my message to take me back to the contol I want to enter the correct data.

    DoCmd.GoToControl "ContolsName"




    Surf
    How would you do this validation at table level ?
    Skharva

  6. #6
    Join Date
    Mar 2004
    Location
    Greenville, SC
    Posts
    271

    Cool Table level

    So your saying the user types into a table vs. a form? I am not sure where you would put code in a table?


    Surf
    Gotta to do some code

  7. #7
    Join Date
    Sep 2003
    Location
    Raleigh, NC
    Posts
    183

    Thumbs up Re: Table level

    Originally posted by surfacesys
    So your saying the user types into a table vs. a form? I am not sure where you would put code in a table?


    Surf
    I figure it out . Thanks for your help
    Skharva

Posting Permissions

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