0

I'm working with this code for Validating a msktxtbox for Date. Everything works fine but what really annoys me is that after the msgbox pops out and user clicks ok, the focus does not go to mskDOB. it goes to the next "TAB INDEX" control. WHy is it doing it? How do I fix it?

Dim datCurrentDate As Date
datCurrentDate = Format(Now, "MM/DD/YYYY")
If Not (IsDate(mskDOB.Text)) Then
    MsgBox "Please check the Date, and re-enter again", vbInformation, "Error"
    mskDOB.SetFocus
    Exit Sub
    Else
        If Format(CDate(mskDOB.Text), "MM/DD/YYYY") >= datCurrentDate Then
            MsgBox "Please check the Date, and re-enter again", vbInformation, "Error"
            mskDOB.SetFocus
            Exit Sub
        End If
End If
barry17
  • 153
  • 2
  • 15

1 Answers1

1

Instead of using mskDOB.SetFocustry using cancel = true.

I tried posting this as a comment, but I dont have enough reputation to post a comment and hence I have posted this as an answer

Kumar C
  • 100
  • 2
  • 13