This topic is locked

List On Load Event

3/28/2007 7:16:15 PM
ASPRunnerPro General questions
BeachyLife author

I calculate a member's age on both the Add and Edit pages using the Before Record Added event and the Before Record Edited events (see below). How do I show the member's correct age as of today on the List page? It seems that the only way the member's age shows correctly is when his record is edited and therefore the Before Edit event is executed.
ADD event:

Function BeforeAdd(dict)

str = "SELECT DateDiff('d','" & dict("RDOB") & "', Date())/365.25 AS Age FROM Roster"

Set rsTemp = server. CreateObject ( "ADODB.Recordset" )

rsTemp. open str , dbConnection

dict("RAge") = rsTemp("Age")
str = "SELECT DateDiff('d','" & dict("RRankDate") & "', Date())/30 AS CTIG FROM Roster"

Set rsTemp = server. CreateObject ( "ADODB.Recordset" )

rsTemp. open str , dbConnection

dict("RCurrTIG") = rsTemp("CTIG")
BeforeAdd = True
End Function
EDIT event:

Function BeforeEdit(dict, where)

str = "SELECT DateDiff('d','" & dict("RDOB") & "', Date())/365.25 AS Age FROM Roster"

Set rsTemp = server. CreateObject ( "ADODB.Recordset" )

rsTemp. open str , dbConnection

dict("RAge") = rsTemp("Age")
str = "SELECT DateDiff('d','" & dict("RRankDate") & "', Date())/30 AS CTIG FROM Roster"

Set rsTemp = server. CreateObject ( "ADODB.Recordset" )

rsTemp. open str , dbConnection

dict("RCurrTIG") = rsTemp("CTIG")
BeforeEdit = True
End Function

BeachyLife author 3/28/2007

Figured it out...added two calculated fields at the end of the SQL and then displayed TodaysAge on both the List and View pages. This now gives me the accurate age as of today's date each time the List or View pages are displayed.
Select

...

...

DateDiff('d',[RDOB],Date())/365.25 AS TodaysAge,

DateDiff('d',[RRankDate],Date())/30 AS TodaysTIG

From Roster