Input Valid

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hello all

I have table Employee. in table have record Birthdate type Date/Tim
When i create a input form and i want to check value if user input the birthday smaller 18 the event will notice error

Private Sub Birthdate_AfterUpdate(
year18 = Year(Now()) - Year(birthday
'If year18 < 18 The
MsgBox "check input value!, vbOKOnly, Error
'End I
End Su

But program don't understant birthday variant
please help me fix

Thank

Hoavn
 
Vo Duong Hoa said:
hello all !

I have table Employee. in table have record Birthdate type Date/Time
When i create a input form and i want to check value if user input the
birthday smaller 18 the event will notice error.
Private Sub Birthdate_AfterUpdate()
year18 = Year(Now()) - Year(birthday)
'If year18 < 18 Then
MsgBox "check input value!, vbOKOnly, Error"
'End If
End Sub

But program don't understant birthday variant.
please help me fix

You may need to put the field name birthday in square brackets:

year18 = Year(Now()) - Year([birthday])

Also, I'd rewrite your code to use the BeforeUpdate event. Notice the other
changes as well.

Private Sub Birthdate_BeforeUpdate(Cancel As Integer)
Dim year18 As Integer
year18 = Year(Date) - Year([birthday])
If year18 < 18 Then
MsgBox "check input value!", vbOKOnly, "Error"
Cancel = True
End If
End Sub

The code still has 1 major flaw. It only check the year of birth, not the
age so someone born in December still looks like they are 18 in January of
the same year. Have a look at the DateDiff function built into Access or
better still the Age function at the Access Web:

http://www.mvps.org/access/datetime/date0001.htm
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
Back
Top