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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can Someone Help Me With This Simple Code ?

Status
Not open for further replies.
Jan 21, 2003
3
CY
Hello Everyone,

I'm trying to include this bit of code to check if the person's age is that of a child or an Adult, but it is not working (in an MS Access form), could you please advise me of how to do this as I'm a beginner when it comes to VBA (I can send you the DB if you wish)...

==============================
Private Sub memberTypeCB_Change()

Dim age As Integer


age = Int((date - Me.DOBTxt) / 365)

If age > 5 Then
Me.memberTypeCB = child
ElseIf age < 18 Then
Me.memberTypeCB = child
Else: MsgBox "Please select child subription as this person is between 5 and 18 years old"
End If


End Sub
============================

Is there anyway to do this so when I press a button on a form to enter a record it can check if the person's age is greater than 5 and less than 18 ?. Any help is greatly appreciated, thanks in advance.

Kind Regards,
Veronica
message_4_u2001@yahoo.com
 
Veronica,


age = Int((date - Me.DOBTxt) / 365)

If you want to convert to an integer thwe function is CINT().
You have INT.

age = CInt((date - Me.DOBTxt.text) / 365)



Dan
 
You need to carefull using strings as dates especially if you are in UK or Oz. Anyway does this help

Code:
Dim age As Integer

age = DateDiff("yyyy",  Me.DOBTxt, Date)

If age > 5 And age < 18 Then
    Me.memberTypeCB  = "child"   'or is child a const declared elsewhere
    MsgBox "Please select child subription as this person is between 5 and 18 years old"
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top