Sub AddToDatabase()
Dim FolderName As String, FileName As String
Dim emptyrow As Long
Dim wbDatabase As Workbook
'initialize variables
FolderName = "O:\Customer Operations\Operational Excellence\Reporting\Niki\Payout Productivity\"
FileName = "Payout Productivity.xlsx"
On Error GoTo exitsub
'check file / folder exists
If Not Dir(FolderName & FileName, vbDirectory) = vbNullString Then
Application.ScreenUpdating = False
'open database workbook
Set wbDatabase = Workbooks.Open(FolderName & FileName, ReadOnly:=False)
With wbDatabase
With .Sheets(1)
'get next empty row
emptyrow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
'Export Data to worksheet
.Cells(emptyrow, 1).Value = DateTextBox.Value
.Cells(emptyrow, 2).Value = ComboBox1.Value
.Cells(emptyrow, 3).Value = HoursWorkedTextBox.Value
.Cells(emptyrow, 4).Value = CompleteServicePlansTextBox.Value
.Cells(emptyrow, 5).Value = DualAssetTextBox.Value
.Cells(emptyrow, 6).Value = ServicePanFailedTextBox.Value
.Cells(emptyrow, 7).Value = Proofsand903sTextBox.Value
.Cells(emptyrow, 8).Value = RenamingTextBox.Value
.Cells(emptyrow, 9).Value = PriorityPayoutTextBox.Value
.Cells(emptyrow, 10).Value = PayoutQueriesTextBox.Value
.Cells(emptyrow, 11).Value = CancellationTextBox.Value
.Cells(emptyrow, 12).Value = BackoutsTextBox.Value
.Cells(emptyrow, 13).Value = ManualContrasTextBox.Value
.Cells(emptyrow, 14).Value = RemitsTextBox.Value
.Cells(emptyrow, 15).Value = FigureFixesTextBox.Value
.Cells(emptyrow, 16).Value = SPQueriesTextBox.Value
.Cells(emptyrow, 17).Value = SPManualLoadsTextBox.Value
.Cells(emptyrow, 18).Value = SPInvoicesTextBox.Value
.Cells(emptyrow, 19).Value = SPCancellationsTextBox.Value
.Cells(emptyrow, 20).Value = RentalAmendmentsTextBox.Value
.Cells(emptyrow, 21).Value = VDATextBox.Value
.Cells(emptyrow, 22).Value = ICRTextBox.Value
.Cells(emptyrow, 23).Value = FCMChequesTextBox.Value
.Cells(emptyrow, 24).Value = NBCampaignAutorisationTextBox.Value
.Cells(emptyrow, 25).Value = PostTextBox.Value
.Cells(emptyrow, 26).Value = A8ManualLoadsTextBox.Value
.Cells(emptyrow, 27).Value = A8ActivationsTextBox.Value
.Cells(emptyrow, 28).Value = SeperatingLettersTextBox.Value
.Cells(emptyrow, 29).Value = DeclineReportTextBox.Value
.Cells(emptyrow, 30).Value = iLearnTextBox.Value
.Cells(emptyrow, 31).Value = TrainingTextBox.Value
.Cells(emptyrow, 32).Value = SupportTextBox.Value
.Cells(emptyrow, 33).Value = GeneralLedgerTextBox.Value
.Cells(emptyrow, 34).Value = TextBox7.Value
.Cells(emptyrow, 35).Value = MeetingTextBox.Value
.Cells(emptyrow, 36).Value = PDRTextBox.Value
.Cells(emptyrow, 38).Value = OtherTextBox.Value
.Cells(emptyrow, 37).Value = RCHPendingTextBox.Value
.Cells(emptyrow, 39).Value = RCHChequesTextBox.Value
.Cells(emptyrow, 40).Value = RCHBackoutsTextBox.Value
.Cells(emptyrow, 41).Value = RCHLateLoadsTextBox.Value
.Cells(emptyrow, 42).Value = NotesTextBox.Value
End With
'close & save
.Close True
End With
'report success
MsgBox "Record Added To Database", 48, "Record Added"
Else
'report file not found
MsgBox FolderName & FileName & Chr(10) & Chr(10) & "File Not Found", 48, "File Not Found"
End If
'clear object from memory
Set wbDatabase = Nothing
exitsub:
'close database if still open
If Not wbDatabase Is Nothing Then wbDatabase.Close False
Application.ScreenUpdating = True
'tell user what went wrong
If Err > 0 Then MsgBox (Error(Err)), 48, "Error"
End Sub