简体   繁体   中英

setting focus in txtboxes in vb6?

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

Instead of using mskDOB.SetFocus try 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM