Public Function get_MonthsConsecutive(in_Provider, in_Level, in_Type, in_Date) As Integer
ret = 1
' return value, default of 1 for itself
counter_i = 0
' counter variable to search through next/previous months
tmp_Found = 1
' trigger to stop searching for consecutive months
While tmp_Found > 0
dt_Check = DateAdd("m", counter_i + 1, in_Date)
str_Criteria = "[Level of Care]='" & in_Level & "' AND [TrendingDate]=#" & dt_Check & "# AND [Type]='" & in_Type & "' AND [Discharging Provider Name]='" & in_Provider & "'"
tmp_Found = DCount("[Discharging Provider Name]", "[Aftercare Report data]", str_Criteria)
If tmp_Found > 0 Then counter_i = counter_i + 1
Wend
ret = ret + counter_i
tmp_Found = 1
counter_i = 0
While tmp_Found > 0
dt_Check = DateAdd("m", counter_i - 1, in_Date)
str_Criteria = "[Level of Care]='" & in_Level & "' AND [TrendingDate]=#" & dt_Check & "# AND [Type]='" & in_Type & "' AND [Discharging Provider Name]='" & in_Provider & "'"
tmp_Found = DCount("[Discharging Provider Name]", "[Aftercare Report data]", str_Criteria)
If tmp_Found > 0 Then counter_i = counter_i - 1
Wend
ret = ret - counter_i
get_MonthsConsecutive = ret
End Function