how to filter data

D

datin

Hi,
currently Im developing a database for HR.I need to display only child that
will attend public examination in my report.Pls help me to solve this problem.

Private Sub DOB_AfterUpdate()
Dim age1 As String
Me!Age = DateDiff("yyyy", DOB, Date) + Int(Format(DOB, "ddmm") >
Format(Date, "ddmm"))
Refresh
If Me!Age = 15 Then
Me!Exam = "PMR"
Else
If Me!Age = 17 Then
Me!Exam = "SPM"
Else
If Me!Age = 12 Then
Me!Exam = "UPSR"
Else
If Me!Age = 19 Then
Me!Exam = "STPM"
Else
Me!Exam = ""
End If
End If
End If
End If
End Sub


thank you and regards
 
M

MGFoster

datin said:
Hi,
currently Im developing a database for HR.I need to display only child that
will attend public examination in my report.Pls help me to solve this problem.

Private Sub DOB_AfterUpdate()
Dim age1 As String
Me!Age = DateDiff("yyyy", DOB, Date) + Int(Format(DOB, "ddmm") >
Format(Date, "ddmm"))
Refresh
If Me!Age = 15 Then
Me!Exam = "PMR"
Else
If Me!Age = 17 Then
Me!Exam = "SPM"
Else
If Me!Age = 12 Then
Me!Exam = "UPSR"
Else
If Me!Age = 19 Then
Me!Exam = "STPM"
Else
Me!Exam = ""
End If
End If
End If
End If
End Sub

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You didn't state your problem, nor the results you desired, only the
solution you've developed.

Some suggestions (not solutions to your unstated problem):

A more accurate way to get the age is with this formula:

Year(Now())-Year(birthdatefield) + (DateSerial(Year(Now()),
Month(birthdatefield), Day(birthdatefield))>Now())

An easier (on the eye) way to select from column B, based on value in
column A:

Switch(Age=12,"UPSR",Age=15,"PMR",Age=17,"SPM",Age=19,"STPM")

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBSNH8CoechKqOuFEgEQIo8gCgozNCq7T893rNvVR4wJHrpO0wFEUAoPLd
E8RhR4gb32S6CTB3E8npfGFw
=gPPv
-----END PGP SIGNATURE-----
 
A

Access101

I like MGFoster's DateSerial solution, and here's some additions in my style
of coding:
Private Sub DOB_AfterUpdate()

'Me!Exam should show as UPSR in this example

Dim intExam(20) As String, birthdatefield As Date, age As Integer

intExam(12) = "UPSR"
intExam(15) = "PMR"
intExam(17) = "SPM"
intExam(19) = "STPM"

birthdatefield = #11/17/1995#

age = Year(Now()) - Year(birthdatefield) + (DateSerial(Year(Now()),
Month(birthdatefield), Day(birthdatefield)) > Now())

Me!Exam = intExam(age)

End Sub
 

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