Question : Undefined Function in Expression in Word 2007 Mail Merge from Access 2007

Hi, I'm using a custom function to calculate age between two dates in Access. The custom function works fine in an Access 2007 query, but when I pull it over into a Word 2007 mail merge, it throws up the error "Error has occured: Undefined function 'AgeCalc' in expression."

In the Access query, the function is called with:
AGE: AgeCalc([DOB],[APPTDATE])

In the Access VBA module, the function is written as:

Public Function AgeCalc(Bdate, OtherDate) As Integer
' Returns the Age in years between 2 dates
' Doesn't handle negative date ranges i.e. Bdate > DateToday

    If Month(OtherDate) < Month(Bdate) Or (Month(OtherDate) = _
                Month(Bdate) And Day(OtherDate) < Day(Bdate)) Then
            Age = Year(OtherDate) - Year(Bdate) - 1
    Else
            Age = Year(OtherDate) - Year(Bdate)
    End If
End Function

Any help would be appreciated. Thanks!!

Answer : Undefined Function in Expression in Word 2007 Mail Merge from Access 2007

Hello rmock123,

Try redoing the query to avoid the UDF.  You could use an expression such as:

IIf(Month(OtherDate) < Month(Bdate) Or (Month(OtherDate) = Month(Bdate) And Day(OtherDate) < Day(Bdate)), Year(OtherDate) - Year(Bdate) - 1, Year(OtherDate) - Year(Bdate))

Regards,

Patrick
Random Solutions  
 
programming4us programming4us