I might not be able to do this because of the "DATE" data-type of DOE, but I thought I'd post the question anyway. As one can see, I want to get the average value of the CLng of the "DOE" fields in the table "Ledgers". "AvgCriteria" seems to be formatting okay, as observed in Debug. The function is referenced as the RecordSource of an unbound text box. e.g., =PurchaseDate([InvstID])
Is the expression "CLng([DOE])" valid as coded?
BTW, TType is an autonumber field, so it's data type long.
Code:
Private Function PurchaseDate(ID As Long) As Date
Dim AvgCriteria As String
Dim AvgValue
'*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
' For the given investment (ID), we need to calculate the average purchase date based on all "buy's"
' prior to the current year being processed, see "ForYear". The process is simply a case of selecting all
' the "buy" DOE's for the current investment and calculating the average.
'*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
AvgCriteria = "[InvstID] = " & ID & " AND [TType] = 1"
AvgValue = DAvg("CLng([DOE])", "Ledgers", AvgCriteria)
PurchaseDate = CDate(AvgValue)
End Function