CONDITIONS:
1. deny if Emp has had any for the year
2. DENY if emp app Elapse < 30 days
3. ok if emp app date < 30 days STARTDATE
make a query,qsEmpLeaveYr, to get Emps and their leave year, :
select EmpID, Year(sStartDate) as Yr from TblEmpLeaveSchedule
On the entry form, the user enters leave data then
validate the App request by clicking button:
Code:
sub btnAppy_click()
dim vHasThisYr, vElapse, vDaysAway
'check all conditions above from the entry form:
vHasThisYr = Dlookup("[EmpId]","qsEmpLeaveYr","[EmpId]=" & txtID & " and [Yr]=" & Year(txtStartDate))
if IsNull( vHasThisYr ) then
'ok for app this year ,rule 1
'now check elapsed leave time
vElapse = DateDiff("d",txtStartDate, txtEndDate)
if vElapse < 30 then 'rule 3, ok if leave <30
msgbox "Leave is too short"
else
vDaysAway= DateDiff("d",date(), txtStartDate)
if vDaysAway <30 then
msgbox "Leave request is too close to leave"
else
docmd.openquery "qaAddRqst2Schedule"
endif
endif
ELSE
msgbox "Applicant aleady took leave this year"
endif
end sub