Results 1 to 4 of 4

Thread: Validating Dates in Textboxes

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2003
    Posts
    89

    Arrow Validating Dates in Textboxes

    Hello,

    I tried this birthdate validation code but it still pops up a message box when I correctly enter a date in the same format of


    Year-Month-Day

    VB Code:
    1. 'Validating Date of Birth so the format should be Year-Month-Day
    2. Private Sub txtDOB_Validate(Cancel As Boolean)
    3.     If txtDOB.Text <> Format$("yyyy-MM-dd") Then
    4.         MsgBox "The Date of Birth (DOB) must be of this format:
    5.         Year-Month-Day.", vbInformation, "Validation"
    6.         txtDOB.TabIndex = 10        
    7.     End If
    8. End Sub

    Any Suggestions? Thanks

    chris

  2. #2
    Addicted Member
    Join Date
    Aug 2003
    Location
    USA
    Posts
    145
    VB Code:
    1. If txtDOB <> Format(txtDOB, "yyyy-MM-dd") Then

    That worked for me. (Change your IF statement to that one).

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Let me suggest that you change the error message from

    MsgBox "The Date of Birth (DOB) must be of this format:
    Year-Month-Day.", vbInformation, "Validation"


    to

    MsgBox "The Date of Birth (DOB) must be of this format:
    yyyy-mm-dd.", vbInformation, "Validation"

    That way people won't wonder why 03-11-01 doesn't work.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 2003
    Posts
    89
    great it worked

Posting Permissions

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



Click Here to Expand Forum to Full Width