Dim strMsg As String
Dim strSQL As String
Dim strAppend As String
Dim strDelete As String
Dim strDate As String
Dim strLoc As String
Dim strFile As String
Dim iMessage As String
Dim strMax As String
strLoc = "E:\MIS\DataFiles\CPU\"
strFile = strLoc & Format(Me.txtMonthEnding, "YYYYMM") & "_monthly_sbt.csv"
strDate = "#" & DateSerial(Year(Me.txtMonthEnding), Month(Me.txtMonthEnding), Day(Me.txtMonthEnding)) & "#"
strMsg = "Information already entered for " & Format(Me.txtMonthEnding, "MMMM YYYY") & " will be deleted"
strMsg = strMsg & " and replaced with imported CPU data."
strMsg = strMsg & vbCrLf & "Would you like to continue?"
'strSQL
strSQL = "UPDATE tblSBTMonthlyCPU SET [Month Ending Date] = " & strDate
'strAppend
strAppend = "INSERT INTO tblCPUMonthlyCharges (COID, [Company Name], [Net Excess Minutes], [Monthly Charge]," _
& " [Month Ending Date])"
strAppend = strAppend & "SELECT tblSBTMonthlyCPU.COID, tblSBTMonthlyCPU.[Company Name], " _
& " tblSBTMonthlyCPU.[Net Excess Minutes], tblSBTMonthlyCPU.['$$ Charge'], tblSBTMonthlyCPU.[Month Ending Date]"
strAppend = strAppend & " FROM tblSBTMonthlyCPU"
'strDelete
strDelete = "DELETE * FROM tblCPUMonthlyCharges"
strDelete = strDelete & " WHERE Month([Month Ending Date]) = " & Month(Me.txtMonthEnding)
strDelete = strDelete & " AND Year([Month Ending Date]) = " & Year(Me.txtMonthEnding)
On Error GoTo ImportErr
'Does data exist for this month
If DCount("ID", "tblCPUMonthlyCharges", "Month([Month Ending Date]) = " & Month(Me.txtMonthEnding) _
& " And Year([Month Ending Date]) = " & Year(Me.txtMonthEnding)) > 0 Then
If MsgBox(strMsg, vbYesNo, "Replace With New") = vbYes Then
GoTo ImportUpdate
End If
Else
GoTo ImportUpdate
End If
ImportExit:
DoCmd.SetWarnings True
Exit Sub
ImportUpdate:
'ImportMonthly_CPU_SBT
DoCmd.SetWarnings False
'Delete Old
DoCmd.RunSQL "DELETE * FROM tblSBTMonthlyCPU"
'Import New
DoCmd.TransferText acImportDelim, , "tblSBTMonthlyCPU", strFile, True
'Insert Date
DoCmd.RunSQL strSQL
'Delete any information from current month in tblCPUMonthlyCharges
DoCmd.RunSQL strDelete
'Append tblCPUMonthlyCharges
DoCmd.RunSQL strAppend
MsgBox "Update Completed Without Error"
'Close
DoCmd.Close acForm, "frmImportCPUInstructions2"
GoTo ImportExit
ImportErr:
MsgBox Error$
GoTo ImportExit