4/15/2010

Sliding Expiration Dates

Bradford County wants to institute a policy of always setting the Expire Date six months out from the last completed inspection for a building permit. The idea being that this would make it easy to run a report at any time using the Expire Date to find out which permits were in danger of expiring because of no activity in six months. The script below was designed for the "Close" button option of the Building database. It checks to find the most recent Last Inspection date in the Inspection Details database and then compares that with the current Expire Date. If the gap is less than six months it displays a message saying that the Expire Date should be changed and lists the date it should be changed too. This script uses "Building" as the Module, "Building" as the Screen, and "Close" as the Action.

myanswer = 0
mycode = id_code
select max(last_insp) from detail1;
where detail1.id_code = mycode into array mydate
mylast = mydate(1)
if not empty(mylast) and mylast > (exp_date - 183)
myanswer = messagebox("Last inspection was "+dtoc(mylast);
+chr(13)+"New expire should be "+dtoc(mylast +183);
+chr(13)+"Do you want to fix it?",68,"New Expiration Needed")
endif
use in detail1
if myanswer = 6
proceedwithclose = .F.
replace exp_date with mylast+183
buildscreen.isediting = .T.
buildscreen.refresh
endif

There are Sliding Expire Date tutorials in the Tutorial section of our web site for both ZP 32 and ZP SQL. These tutorials cover this topic at much greater length.