Note: Use DTpicker control.
Ans:
Dim dob, curdate As Date
Dim d1, m1, y2, d2, m2, y1, d3, m3, y3 As Integer
Private Sub cmdAge_Click ()
dob = CDate(txtDob. Text) curdate = CDate(txtCDate.Text) d1 = Day(dob) m1 = Month (dob) y1 = Year (dob) d2 = Day(curdate)
y2 = Year(curdate)
If d1 > d2 Then d2 = d2 + 30 m2 = m2 - 1 End If
If m1 > m2 Then
m2 = m2 + 12 y2 = y2 - 1
End If
m3 = m2 - m1 Y3 = Y2 - Y1 d3 = d2 - d1 txtDay. Text = d3 txtMonth.Text = m3 txtYear. Text = y3 End Sub
Private Sub txtCDate_GotFocus ()
txtCDate. Text = Date
End Sub
Private Sub txtDob_Vali date (Cancel As Boolean)
If IsDate(txtDob.Text) = False Then MsgBox "Enter The Valid date" txtDob. Text = Clear txtDob.SetFocus
End If
End Sub
No comments:
Post a Comment