Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: Entering wrong date ie 30-2-19 (30-Feb-2019) in txtDate.text it displays as 19-Feb-1930 instead of showing error msg
Thanks Thanks: 0 Likes Likes: 0

  1. #11
    Board Regular
    Join Date
    Apr 2016
    Posts
    60
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Entering wrong date ie 30-2-19 (30-Feb-2019) in txtDate.text it displays as 19-Feb-1930 instead of showing error msg

    welshgasman

    What I was trying to point out that eventually the 2 digit year test is going to fail. By that time you would likely be using new software. :D
    Only you know your data, so if there is a chance of someone entering 01-01-99 then which century is that.? I would hazard a guess as to 1999. If you are putting dates in as 2099 how long do you think your software is going to run?


    If it were me, I would create a dedicated function that would work out the correct date, allow for -,. & / delimiters etc and call in the AfterUpdate event of the controls.
    Once written and tested, that should be it.
    Thanks for your reply. I am not a champion as you guys. Still learning VBA for excel from the champion members here.
    if you have dedicated function to share to set the correct date will appreciate it.
    Last edited by SamDsouza; Jun 17th, 2019 at 11:49 AM.

  2. #12
    Board Regular
    Join Date
    May 2013
    Posts
    607
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Entering wrong date ie 30-2-19 (30-Feb-2019) in txtDate.text it displays as 19-Feb-1930 instead of showing error msg

    I don't. If you look at my signature, I am not an expert at Access either. However I google and find something and amend to suit. On this occasion that would not likely work. Perhaps you can glean something from here https://powerspreadsheets.com/vba-format-date/

    I would break the problem down to small parts.

    1. Find out what delimiter is being used with Instr function.
    2. Split the string using the delimiter with the Split function.
    3. Rebuild the date from it's respective parts.
    4. Test for valid date for the rebuilt value.
    5. Pass rebuilt value back to calling code.

    Then post the working code back here in case it can help someone else. :D
    Office 2007
    Access novice. Sometimes trying to give something back

  3. #13
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    4,508
    Post Thanks / Like
    Mentioned
    41 Post(s)
    Tagged
    12 Thread(s)

    Default Re: Entering wrong date ie 30-2-19 (30-Feb-2019) in txtDate.text it displays as 19-Feb-1930 instead of showing error msg

    Quote Originally Posted by SamDsouza View Post
    Thanks DanteAmor for your suggestion for adding another validation. Whats happening is i ve to compulsory add 10 digits
    What is desired is Entering dates with the flexibility
    as
    1. 25-01-01 result as 25-Jan-2001
    2. 2-3-14 result as 02-Mar-2014
    3.02-03-2014 result as 02-Mar-2014
    4. 02-3-14 result as 02-Mar-2014
    5. 2-03-14 result as 02-Mar-2014

    only if wrong date entered by mistake then Error Msg
    You can use a control like Dtpicker or Monthview to get a date, and that way you do not have to validate correct dates.
    Regards Dante Amor

  4. #14
    Board Regular
    Join Date
    Oct 2009
    Location
    Midlands, UK
    Posts
    7,362
    Post Thanks / Like
    Mentioned
    17 Post(s)
    Tagged
    3 Thread(s)

    Default Re: Entering wrong date ie 30-2-19 (30-Feb-2019) in txtDate.text it displays as 19-Feb-1930 instead of showing error msg

    Something like this makes 30-2-19 invalid but works on your other examples:

    Code:
    x = "30-2-19"
    dateArr = Split(x, "-")
        
    If dateArr(2) > 29 Then
        dateArr(2) = 19 * 100 + dateArr(2)
    Else
        dateArr(2) = 20 * 100 + dateArr(2)
    End If
    
    If Month(DateSerial(dateArr(2), dateArr(1), dateArr(0))) <> Val(dateArr(1)) Then
        MsgBox "Invalid date entered"
        Exit Sub
    Else
        myDate = DateSerial(dateArr(2), dateArr(1), dateArr(0))
    End If

  5. #15
    Board Regular
    Join Date
    Apr 2016
    Posts
    60
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Entering wrong date ie 30-2-19 (30-Feb-2019) in txtDate.text it displays as 19-Feb-1930 instead of showing error msg

    Thank you guys for your wonderful help and suggestions.

    SamD

  6. #16
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    4,508
    Post Thanks / Like
    Mentioned
    41 Post(s)
    Tagged
    12 Thread(s)

    Default Re: Entering wrong date ie 30-2-19 (30-Feb-2019) in txtDate.text it displays as 19-Feb-1930 instead of showing error msg

    Quote Originally Posted by SamDsouza View Post
    Thank you guys for your wonderful help and suggestions.

    SamD
    I'm glad to help you. Thanks for the feedback.
    Regards Dante Amor

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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