Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I'm not sure what this problem is? It occurs when lose Focus

Status
Not open for further replies.

eelsar

Technical User
May 20, 2002
36
0
0
US
I am having the following problem:
When I tab from box to box after I lose focus on the box that I ask the user to enter the childs date of birth, a runtime error, "Error 13" occurs (a data type mismatch error). If I manually click in each box and don't tab, this problem does not occur.
Here is the code that seems to be problematic when I tab
(someone very kindly on tek-tips gave me this code to accurately figure out someones Age - it works well!)

Private Sub maskDateOfBirthChild_LostFocus()
Dim basAge As String
basAge = DateDiff("yyyy", maskDateOfBirthChild.Text, Date)
basAge = basAge + (DateSerial(Year(Date), Month(maskDateOfBirthChild.Text), Day(maskDateOfBirthChild.Text)) > Date)
txtAgeChild.Text = basAge
End Sub

If I manually click in the date of birth box and enter the date of birth and then click in any other box the accurate age shows up in the age box. However if I tab into the date of birth box, enter the date of birth, the press tab again the runtime error "Error 13" shows up.

Can anyone help me solve this problem?
Thank you!

 
Private Sub maskDateOfBirthChild_LostFocus()
Dim basAge As String
If Not IsDate(maskDateOfBirthChild.Text) Then
MsgBox "Please enter a valid date of birth!", vbInformation
maskDateOfBirthChild.SetFocus
maskDateOfBirthChild.SelStart = 0
maskDateOfBirthChild.SelLength = _
Len(maskDateOfBirthChild.Text)
Exit Sub
End If
basAge = DateDiff("yyyy", maskDateOfBirthChild.Text, Date)
basAge = basAge + (DateSerial(Year(Date), Month(maskDateOfBirthChild.Text), Day(maskDateOfBirthChild.Text)) > Date)
txtAgeChild.Text = basAge
End Sub Swi
 
I tried your code addition and it worked.
Thank you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top