Status query by date (1 Viewer)

ndduke

New member
Local time
Today, 03:53
Joined
Mar 6, 2017
Messages
2
I currently have a status query in my database to automatically show an individuals status "Current", "Suspended", "Expired" based on the date of their last exam.

I'm trying to get a fourth status to show, but haven't had any luck with the code. I am using MS Access 2013.

I currently show "CURRENT" for those whose date is less than 180 days, "SUSPENDED" if their date is between 181 and 365 days and Expired if over 365 days.

What I am trying to do is show Expired for dates between 365 and 730 days and add an "INACTIVE" status for those 731 days or greater... I haven't had much luck... below is what I am using right now and it works great, but trying to expand the status.

Status: IIf(DateDiff("d",[Cert_CurrencyDate],Date())<=180,"CURRENT",IIf(DateDiff("d",[Cert_CurrencyDate],Date())>=181 And DateDiff("d",[Cert_CurrencyDate],Date())<365,"SUSPENDED","EXPIRED"))

Thanks in advance for any help.
Nathan
 
Last edited:

Ranman256

Well-known member
Local time
Today, 06:53
Joined
Apr 9, 2015
Messages
4,339
instead of building nested IIFs, in the query ,qsData, make an extra field for DAYS:DateDiff("d",[Cert_CurrencyDate],Date())

then make another query based on the above query qsData, that has your limits, but now its:
IIf([Days])<=180, "CURRENT", IIf([Days]>=181 And [Days]<365), "SUSPENDED",IIf([Days]>365 And [Days]<730), "INACTIVE","EXPIRED")))


OR
You can build a custom function to get the results. place this code into a module.
usage in query:
STATUS: getStatusDays([Days])

Code:
function getStatusDays(pvDays)
select case pvDays
  case  <= 180 
   vRet = "CURRENT"

  case  >= 181 AND <365
   vRet = "SUSPENDED

  case  >= 365 AND <730
    vRet = "EXPIRED

 case  > 365 AND <731
    vRet = "INACTIVE
  case  else
end select
getStatusDays = vRet
end function
 

sneuberg

AWF VIP
Local time
Today, 03:53
Joined
Oct 17, 2014
Messages
3,506
Ranman256 got here faster than me but I'll give you my version anyway.


Code:
Public Function GetStatus(Cert_CurrencyDate As Variant) As Variant

Dim DaysSince As Long
If IsNull(Cert_CurrencyDate) Then
    GetStatus = Null
    Exit Function
End If
DaysSince = DateDiff("d", [Cert_CurrencyDate], Date)
If DaysSince <= 180 Then
    GetStatus = "CURRENT"
ElseIf DaysSince < 365 Then
    GetStatus = "SUSPENDED"
ElseIf DaysSince < 730 Then
    GetStatus = "EXPIRED"
Else
    GetStatus = "INACTIVE"
End If

End Function


Demo database attached
 

Attachments

  • ExamStatus.accdb
    392 KB · Views: 61

ndduke

New member
Local time
Today, 03:53
Joined
Mar 6, 2017
Messages
2
Thanks to all... they all worked... I'm fairly new to Access and trying to teach myself... So I appreciate the quick and useful responses.
 

Users who are viewing this thread

Top Bottom