C
charleswoods via AccessMonster.com
First of all, this function has worked for years... After returning from
vacation, I find that this function which is used to determine a person's age
at the time they visit our hospital, doesn't work anymore. I have racked my
brain trying to find an answer to why this has stopped working. The
application which feeds the tables queried will not allow different data
types to be entered into the tables.
Function Age(VarBirthdate As Date, VarAdate As Date) As Integer
Dim VarAge As Variant
If IsNull(VarBirthdate) Then Age = 0: Exit Function
VarAge = DateDiff("yyyy", VarBirthdate, VarAdate)
If DateSerial(Year(VarAdate), Month(VarAdate), Day(VarAdate)) < DateSerial
(Year(VarAdate), Month(VarBirthdate), Day(VarBirthdate)) Then
VarAge = VarAge - 1
End If
Age = Val(VarAge)
End Function
Here is a sample query that returns this error:
SELECT EMSTAT_ARCHIVE_CHART.CHRTNO, Age([EMSTAT_ARCHIVE_PATIENT]![DOB],
[EMSTAT_ARCHIVE_CHART]![ARRVDATE]) AS AGEPT, EMSTAT_ARCHIVE_CHART.ARRVDATE
INTO tblFC2006
FROM ((EMSTAT_ARCHIVE_PATIENT INNER JOIN EMSTAT_ARCHIVE_CHART ON
EMSTAT_ARCHIVE_PATIENT.PTNTID = EMSTAT_ARCHIVE_CHART.PTNTID) INNER JOIN
(EMSTAT_ARCHIVE_OI_HEADER INNER JOIN EMSTAT_ARCHIVE_OI_DETAIL ON
EMSTAT_ARCHIVE_OI_HEADER.OI_HEADER_ID = EMSTAT_ARCHIVE_OI_DETAIL.OI_HEADER_ID)
ON EMSTAT_ARCHIVE_CHART.CHRTNO = EMSTAT_ARCHIVE_OI_HEADER.CHARTNO) INNER JOIN
EMSTAT_ARCHIVE_LOCATION ON EMSTAT_ARCHIVE_OI_DETAIL.VALUE =
EMSTAT_ARCHIVE_LOCATION.LOCATID
WHERE (((EMSTAT_ARCHIVE_OI_HEADER.OD_HEADER_ID)="ADMINCHGROOM") AND (
(EMSTAT_ARCHIVE_OI_DETAIL.OD_DETAIL_ID)="ROOM"))
GROUP BY EMSTAT_ARCHIVE_CHART.CHRTNO, Age([EMSTAT_ARCHIVE_PATIENT]![DOB],
[EMSTAT_ARCHIVE_CHART]![ARRVDATE]), EMSTAT_ARCHIVE_CHART.ARRVDATE
HAVING (((EMSTAT_ARCHIVE_CHART.ARRVDATE) Between #1/1/2006# And #1/5/2006#));
This query will work fine if I remove the function.
Any help is greatly appreciated!
vacation, I find that this function which is used to determine a person's age
at the time they visit our hospital, doesn't work anymore. I have racked my
brain trying to find an answer to why this has stopped working. The
application which feeds the tables queried will not allow different data
types to be entered into the tables.
Function Age(VarBirthdate As Date, VarAdate As Date) As Integer
Dim VarAge As Variant
If IsNull(VarBirthdate) Then Age = 0: Exit Function
VarAge = DateDiff("yyyy", VarBirthdate, VarAdate)
If DateSerial(Year(VarAdate), Month(VarAdate), Day(VarAdate)) < DateSerial
(Year(VarAdate), Month(VarBirthdate), Day(VarBirthdate)) Then
VarAge = VarAge - 1
End If
Age = Val(VarAge)
End Function
Here is a sample query that returns this error:
SELECT EMSTAT_ARCHIVE_CHART.CHRTNO, Age([EMSTAT_ARCHIVE_PATIENT]![DOB],
[EMSTAT_ARCHIVE_CHART]![ARRVDATE]) AS AGEPT, EMSTAT_ARCHIVE_CHART.ARRVDATE
INTO tblFC2006
FROM ((EMSTAT_ARCHIVE_PATIENT INNER JOIN EMSTAT_ARCHIVE_CHART ON
EMSTAT_ARCHIVE_PATIENT.PTNTID = EMSTAT_ARCHIVE_CHART.PTNTID) INNER JOIN
(EMSTAT_ARCHIVE_OI_HEADER INNER JOIN EMSTAT_ARCHIVE_OI_DETAIL ON
EMSTAT_ARCHIVE_OI_HEADER.OI_HEADER_ID = EMSTAT_ARCHIVE_OI_DETAIL.OI_HEADER_ID)
ON EMSTAT_ARCHIVE_CHART.CHRTNO = EMSTAT_ARCHIVE_OI_HEADER.CHARTNO) INNER JOIN
EMSTAT_ARCHIVE_LOCATION ON EMSTAT_ARCHIVE_OI_DETAIL.VALUE =
EMSTAT_ARCHIVE_LOCATION.LOCATID
WHERE (((EMSTAT_ARCHIVE_OI_HEADER.OD_HEADER_ID)="ADMINCHGROOM") AND (
(EMSTAT_ARCHIVE_OI_DETAIL.OD_DETAIL_ID)="ROOM"))
GROUP BY EMSTAT_ARCHIVE_CHART.CHRTNO, Age([EMSTAT_ARCHIVE_PATIENT]![DOB],
[EMSTAT_ARCHIVE_CHART]![ARRVDATE]), EMSTAT_ARCHIVE_CHART.ARRVDATE
HAVING (((EMSTAT_ARCHIVE_CHART.ARRVDATE) Between #1/1/2006# And #1/5/2006#));
This query will work fine if I remove the function.
Any help is greatly appreciated!