Select Case Trouble

D

Dave

Access 2007

Trying to get a reaction id age is less the 40 or greater then 72

I am getting NO reaction with this code

Private Sub Q1_AfterUpdate()
Dim age

age = DateDiff("d", [Q1], Date) / 365
Select Case Q1
Case "age < 40"
Forms!frmPage2.pgeIneligible.SetFocus
Case "age > 72"
Forms!frmPage2.pgeIneligible.SetFocus
Reason.Value = "Out of Age Range"
End Select
End Sub


Any assistance?

Thanks

dave
 
D

Dave

I renamed it for the purpose of this post.

it is another page on on the Page Object that has these fields.

Thanks
 
M

Mike Painter

Dave said:
Access 2007

Trying to get a reaction id age is less the 40 or greater then 72

I am getting NO reaction with this code

Private Sub Q1_AfterUpdate()
Dim age

age = DateDiff("d", [Q1], Date) / 365

Others have answered your question but note that using this to determine age
will mean you are wrong half the time on average.

Posted by Ken Getz: ( A long time ago)

Function GetAge(dtmBD as Date) As Integer
GetAge = DateDiff("yyyy", dtmBD, Date) + _
(Date < DateSerial(Year(Date), Month(dtmBD), Day(dtmBD)))
End Function

Basically, this counts on the fact that a True expression has a value of
-1, and so if the current date is less than the birthdate value in the
current year, it subtracts one from the year difference between the two.

If you're using Access 95 or 97, use a Date variable rather than a
variant.

--Ken

GetAge = DateDiff("yyyy", dtmBD, Date) +(Date < DateSerial(Year(Date),
Month(dtmBD),Day(dtmBD)))
 
D

Dave

Thanks for the additional insite

dave

Mike Painter said:
Dave said:
Access 2007

Trying to get a reaction id age is less the 40 or greater then 72

I am getting NO reaction with this code

Private Sub Q1_AfterUpdate()
Dim age

age = DateDiff("d", [Q1], Date) / 365

Others have answered your question but note that using this to determine
age will mean you are wrong half the time on average.

Posted by Ken Getz: ( A long time ago)

Function GetAge(dtmBD as Date) As Integer
GetAge = DateDiff("yyyy", dtmBD, Date) + _
(Date < DateSerial(Year(Date), Month(dtmBD), Day(dtmBD)))
End Function

Basically, this counts on the fact that a True expression has a value of
-1, and so if the current date is less than the birthdate value in the
current year, it subtracts one from the year difference between the two.

If you're using Access 95 or 97, use a Date variable rather than a
variant.

--Ken

GetAge = DateDiff("yyyy", dtmBD, Date) +(Date < DateSerial(Year(Date),
Month(dtmBD),Day(dtmBD)))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top