Sub BuildExcelSheetTop(SheetName As String)
Dim rsSystem As Recordset
Dim TempMonth As Integer
Dim TempYear As Integer
Set xlSht = xlWkbk.Worksheets(SheetName)
Set rsSystem = New Recordset
With rsSystem
.Open "SELECT * FROM t_System", CurrentProject.Connection, adOpenKeyset, adLockReadOnly
xlSht.Range("'" & SheetName & "'!PIN").Value = .Fields("PIN").Value
xlSht.Range("'" & SheetName & "'!SCM").Value = .Fields("SCM").Value
xlSht.Range("'" & SheetName & "'!Hospital").Value = .Fields("FacilityName").Value
xlSht.Range("'" & SheetName & "'!Market").Value = .Fields("Market").Value
xlSht.Range("'" & SheetName & "'!StartDate").Value = Format(.Fields("StartDate").Value, "mm-dd-yy")
xlSht.Range("'" & SheetName & "'!EndDate").Value = fDate_Convert("LastDay", Format(.Fields("EndDate").Value, "mm-dd-yy"))
xlSht.Range("'" & SheetName & "'!AdjDate").Value = .Fields("AdjDate").Value
xlSht.Range("'" & SheetName & "'!RenewalDate").Value = .Fields("RenewalDate").Value
TempYear = Year(.Fields("EndDate").Value) - Year(.Fields("StartDate").Value)
TempYear = TempYear * 12
TempMonth = Month(.Fields("EndDate").Value) - Month(.Fields("StartDate").Value)
TempMonth = TempMonth + 1
xlSht.Range("'" & SheetName & "'!O3").Value = TempMonth + TempYear
gYearCalc = Year(.Fields("AdjDate").Value)
gFirstMonth = 13 - Month(.Fields("AdjDate").Value)
gSecondMonth = 12 - gFirstMonth
gThirdMonth = 0
.Close
End With
End Sub
Sub BuildRateGroups(SheetName As String, strSQLSuffix As String)
Dim rsMap As Recordset
Dim RateGroupCount As Integer
Dim HMOCount As Integer
Dim NonHMOCount As Integer
Dim RowLoop As Long
Set rsMap = New Recordset
With rsMap
.Open "SELECT * from t_Map", CurrentProject.Connection, adOpenKeyset, adLockReadOnly
RateGroupCount = .RecordCount
If RateGroupCount < 1 Then
MsgBox "Please set the parameters before starting the download process.", vbOKOnly, "Rate Group Missing"
Exit Sub
End If
.Close
.Open "SELECT DISTINCT t_Results_Detail.PROD, t_Results_Detail.RATEGRP FROM t_Results_Detail WHERE Prod = 'HMO' AND RATEGRP IS NOT NULL" & strSQLSuffix, CurrentProject.Connection, adOpenKeyset, adLockReadOnly
HMOCount = .RecordCount
.Close
.Open "SELECT DISTINCT t_Results_Detail.PROD, t_Results_Detail.RATEGRP FROM t_Results_Detail WHERE Prod <> 'HMO' AND RATEGRP IS NOT NULL" & strSQLSuffix, CurrentProject.Connection, adOpenKeyset, adLockReadOnly
NonHMOCount = .RecordCount
.Close
End With
'Add space for additional rate group lines on the template.
Set xlSht = xlWkbk.Worksheets(SheetName)
With xlSht
If HMOCount > 1 Then
For RowLoop = 1 To HMOCount - 1
.Range("'" & SheetName & "'!HMOCalcRow").Copy
.Range("'" & SheetName & "'!HMOCalcRow").Insert xlShiftDown
Next
End If
If NonHMOCount > 1 Then
For RowLoop = 1 To NonHMOCount - 1
.Range("'" & SheetName & "'!NonHMOCalcRow").Copy
.Range("'" & SheetName & "'!NonHMOCalcRow").Insert xlShiftDown
Next
End If
End With
Select Case SheetName
Case "CM Savings-ALL"
gHMOCountAll = HMOCount
gNonHMOCountAll = NonHMOCount
Case "CM Savings-FI ONLY"
gHMOCountFI = HMOCount
gNonHMOCountFI = NonHMOCount
Case Else
End Select
End Sub
Sub BuildReconciliation()
Dim rsSummary As Recordset
Dim ColCount As Integer
Dim RowCount As Long
Dim ColLoop As Integer
Dim RowLoop As Long
Set xlSht = xlWkbk.Worksheets("Reconciliation")
xlSht.PageSetup.LeftFooter = xlFileName
xlSht.Range("A1:AZ65536").ClearContents
Set rsSummary = New Recordset
With rsSummary
.Open "SELECT EPDB_PIN, PROD, FUNDING, DOSMO, RATEGRP, NEWRATEGRP, BILLED_AMT FROM t_Results_Detail ORDER BY EPDB_PIN, PROD, FUNDING, DOSMO, RATEGRP, NEWRATEGRP", CurrentProject.Connection, adOpenKeyset, adLockReadOnly
If .EOF Then
MsgBox "No data was returned for the criteria you selected.", vbOKOnly, "No Data Found"
Exit Sub
End If
ColCount = .Fields.Count
RowCount = .RecordCount
.MoveFirst
For ColLoop = 0 To ColCount - 1
xlSht.Cells(1, ColLoop + 1).Value = .Fields(ColLoop).Name
Next
For RowLoop = 0 To RowCount - 1
For ColLoop = 0 To ColCount - 1
xlSht.Cells(RowLoop + 2, ColLoop + 1).Value = .Fields(ColLoop).Value
Next
.MoveNext
Next
.Close
End With
Set rsSummary = Nothing
End Sub
Sub BuildSummary()
Dim rsSummary As Recordset
Dim ColCount As Integer
Dim RowCount As Long
Dim ColLoop As Integer
Dim RowLoop As Long
Set xlSht = xlWkbk.Worksheets("Summary")
xlSht.PageSetup.LeftFooter = xlFileName
xlSht.Range("A1:AZ65536").ClearContents
Set rsSummary = New Recordset
With rsSummary
.Open "SELECT EPDB_PIN, PROD, FUNDING, RG, NEWRG, BILLED_AMT FROM q_Results_Summarized", CurrentProject.Connection, adOpenKeyset, adLockReadOnly
If .EOF Then
MsgBox "No data was returned for the criteria you selected.", vbOKOnly, "No Data Found"
Exit Sub
End If
ColCount = .Fields.Count
RowCount = .RecordCount
.MoveFirst
For ColLoop = 0 To ColCount - 1
xlSht.Cells(1, ColLoop + 1).Value = .Fields(ColLoop).Name
Next
For RowLoop = 0 To RowCount - 1
For ColLoop = 0 To ColCount - 1
xlSht.Cells(RowLoop + 2, ColLoop + 1).Value = .Fields(ColLoop).Value
Next
.MoveNext
Next
.Close
End With
End Sub
Sub BuildDetail(SheetName As String, strSQLSuffix As String)
Dim rsSummary As Recordset
Dim HMOCount As Integer
Dim NonHMOCount As Integer
Dim RowLoop As Long
Dim strSQL As String
Set rsSummary = New Recordset
Select Case SheetName
Case "CM Savings-ALL"
HMOCount = gHMOCountAll
NonHMOCount = gNonHMOCountAll
strSQL = "SELECT * FROM q_Results_Summarized_ByProdRG"
Case "CM Savings-FI ONLY"
HMOCount = gHMOCountFI
NonHMOCount = gNonHMOCountFI
strSQL = "SELECT * FROM q_Results_Summarized_FI_ONLY"
Case Else
End Select
Set xlSht = xlWkbk.Worksheets(SheetName)
With rsSummary
xlSht.PageSetup.LeftFooter = xlFileName
xlSht.Range("J9").Value = gYearCalc & " Contract Period"
xlSht.Range("L9").Value = gYearCalc + 1 & " Contract Period"
xlSht.Range("N9").Value = gYearCalc + 2 & " Contract Period"
.Open strSQL & " WHERE PROD = 'HMO'", CurrentProject.Connection, adOpenKeyset, adLockReadOnly
If Not (.EOF) Then
If HMOCount > 1 And .RecordCount > 1 Then
.MoveFirst
For RowLoop = 0 To HMOCount - 1
xlSht.Range("A11").Offset(RowLoop).Value = fFormatRG(.Fields("RateGrp").Value)
xlSht.Range("C11").Offset(RowLoop).Value = .Fields("Billed_Amt")
xlSht.Range("D11").Offset(RowLoop).Value = .Fields("SumOfBilled_Amt_In_RG").Value
xlSht.Range("G11").Offset(RowLoop).Value = fFormatRG(.Fields("NewRateGrp").Value)
xlSht.Range("J11").Offset(RowLoop).Value = gFirstMonth
xlSht.Range("L11").Offset(RowLoop).Value = gSecondMonth
xlSht.Range("N11").Offset(RowLoop).Value = gThirdMonth
.MoveNext
Next
Else
xlSht.Range("A11").Value = fFormatRG(.Fields("RateGrp").Value)
xlSht.Range("C11").Value = .Fields("Billed_Amt")
xlSht.Range("D11").Value = .Fields("SumOfBilled_Amt_In_RG").Value
xlSht.Range("G11").Value = fFormatRG(.Fields("NewRateGrp").Value)
xlSht.Range("J11").Value = gFirstMonth
xlSht.Range("L11").Value = gSecondMonth
xlSht.Range("N11").Value = gThirdMonth
End If
End If
.Close
.Open strSQL & " WHERE PROD = 'NonHMO'", CurrentProject.Connection, adOpenKeyset, adLockReadOnly
If HMOCount < 1 Then
HMOCount = 1
End If
If Not (.EOF) Then
If NonHMOCount > 1 And .RecordCount > 1 Then
.MoveFirst
For RowLoop = 0 To NonHMOCount - 1
xlSht.Range("A19").Offset(RowLoop + (HMOCount - 1)).Value = fFormatRG(.Fields("RateGrp").Value)
xlSht.Range("C19").Offset(RowLoop + (HMOCount - 1)).Value = .Fields("Billed_Amt")
xlSht.Range("D19").Offset(RowLoop + (HMOCount - 1)).Value = .Fields("SumOfBilled_Amt_In_RG").Value
xlSht.Range("G19").Offset(RowLoop + (HMOCount - 1)).Value = fFormatRG(.Fields("NewRateGrp").Value)
xlSht.Range("J19").Offset(RowLoop + (HMOCount - 1)).Value = gFirstMonth
xlSht.Range("L19").Offset(RowLoop + (HMOCount - 1)).Value = gSecondMonth
xlSht.Range("N19").Offset(RowLoop + (HMOCount - 1)).Value = gThirdMonth
.MoveNext
Next
Else
xlSht.Range("A19").Offset(HMOCount - 1).Value = fFormatRG(.Fields("RateGrp").Value)
xlSht.Range("C19").Offset(HMOCount - 1).Value = .Fields("Billed_Amt")
xlSht.Range("D19").Offset(HMOCount - 1).Value = .Fields("SumOfBilled_Amt_In_RG").Value
xlSht.Range("G19").Offset(HMOCount - 1).Value = fFormatRG(.Fields("NewRateGrp").Value)
xlSht.Range("J19").Offset(HMOCount - 1).Value = gFirstMonth
xlSht.Range("L19").Offset(HMOCount - 1).Value = gSecondMonth
xlSht.Range("N19").Offset(HMOCount - 1).Value = gThirdMonth
End If
End If
xlSht.Range("A16").Offset(HMOCount - 1).RowHeight = 25.5
xlSht.Range("A17").Offset(HMOCount - 1).RowHeight = 25.5
xlSht.Range("A18").Offset(HMOCount - 1).RowHeight = 38.25
xlSht.Range("J17").Offset(HMOCount - 1).Value = gYearCalc & " Contract Period"
xlSht.Range("L17").Offset(HMOCount - 1).Value = gYearCalc + 1 & " Contract Period"
xlSht.Range("N17").Offset(HMOCount - 1).Value = gYearCalc + 2 & " Contract Period"
End With
End Sub
Function fFormatRG(NewRG As Single)
fFormatRG = Format(NewRG, "0.0000")
End Function