Hi,
I'm trying to create a data entry form that will validate the data entered by user. The requirement is as follows:
columns:
Date of Birth, Age, Lastname
validation:
Age = can only accept >4 and <16
computed field:
Age = computed based on Date of Birth and current year.
error tracking:
User may only enter data with age >4 and <16, if not, message will be displayed and focus will go back to "Date of Birth" column.
code:
Option Compare Database
Dim AgeNumber As Integer
Private Sub DOB_AfterUpdate()
AgeNumber = Year(Now()) - Year(Me.DOB)
If AgeNumber > 4 And AgeNumber < 16 Then
Me.AGE = Year(Now()) - Year(Me.DOB)
Else
MsgBox "Can only accept age between 4 and 16 yrs old.", vbInformation, "Error..."
Me.DOB.SetFocus
End If
End Sub
Above script not working and focus will still go to the next column which is "Last Name"
Your help will be very much appreciated.
Thanks,
Rod
I'm trying to create a data entry form that will validate the data entered by user. The requirement is as follows:
columns:
Date of Birth, Age, Lastname
validation:
Age = can only accept >4 and <16
computed field:
Age = computed based on Date of Birth and current year.
error tracking:
User may only enter data with age >4 and <16, if not, message will be displayed and focus will go back to "Date of Birth" column.
code:
Option Compare Database
Dim AgeNumber As Integer
Private Sub DOB_AfterUpdate()
AgeNumber = Year(Now()) - Year(Me.DOB)
If AgeNumber > 4 And AgeNumber < 16 Then
Me.AGE = Year(Now()) - Year(Me.DOB)
Else
MsgBox "Can only accept age between 4 and 16 yrs old.", vbInformation, "Error..."
Me.DOB.SetFocus
End If
End Sub
Above script not working and focus will still go to the next column which is "Last Name"
Your help will be very much appreciated.
Thanks,
Rod