AronGahagan / cpt-dev

Code repository for the ClearPlan Toolbar
https://www.ClearPlanConsulting.com
3 stars 1 forks source link

cptResourceDemand - ensure cptFiscalCalendar.Exceptions.Count > 0 #344

Closed AronGahagan closed 1 year ago

AronGahagan commented 1 year ago

Problem:

User had cptFiscalCalendar but it had no exceptions. Root cause may be the template upload process: investigate.

Function cptCalendarExists(strCalendar As String) As Boolean
  Dim oCalendar As MSProject.Calendar
  On Error Resume Next
  Set oCalendar = ActiveProject.BaseCalendars(strCalendar)
  If cptErrorTrapping Then On Error GoTo err_here Else On Error GoTo 0
  If oCalendar Is Nothing Then
    cptCalendarExists = False
  Else
    cptCalendarExists = True
  End If
exit_here:
  On Error Resume Next
  Set oCalendar = Nothing
  Exit Function
err_here:
  Call cptHandleErr("cptResourceDemand_bas", "cptCalendarExists", Err, Erl)
  Resume exit_here
End Function

Solution:

Function cptCalendarExists(strCalendar As String) As Boolean
  Dim oCalendar As MSProject.Calendar
  Dim strMsg As String

  On Error Resume Next
  Set oCalendar = ActiveProject.BaseCalendars(strCalendar)
  If cptErrorTrapping Then On Error GoTo err_here Else On Error GoTo 0

  If oCalendar Is Nothing Then
    cptCalendarExists = False
  Else
    If oCalendar.Exceptions.Count = 0 Then
      strMsg = "cptFiscalCalendar exists but has no exceptions." & vbCrLf & vbCrLf
      strMsg = strMsg & "Please rebuild it (ClearPlan > Calendars > Fiscal)."
      MsgBox strMsg, vbCritical + vbOKOnly, "No Exceptions"
      oCalendar.Delete
      cptCalendarExists = False
    Else
      cptCalendarExists = True
    End If
  End If

exit_here:
  On Error Resume Next
  Set oCalendar = Nothing
  Exit Function
err_here:
  Call cptHandleErr("cptResourceDemand_bas", "cptCalendarExists", Err, Erl)
  Resume exit_here
End Function

Todo:

AronGahagan commented 1 year ago

Template upload method tested, works fine.