All,
I am having trouble with taking information from a user form and populating that information into a database. Looking for as much feedback as I can get to speed up this process to several minutes 5+ - 10+ minutes depending on the day down to seconds if possible. The bottleneck, from watching the code run, seems to be the individual data transfers from the user form textboxes to the database.
Here is my code:
I am having trouble with taking information from a user form and populating that information into a database. Looking for as much feedback as I can get to speed up this process to several minutes 5+ - 10+ minutes depending on the day down to seconds if possible. The bottleneck, from watching the code run, seems to be the individual data transfers from the user form textboxes to the database.
Here is my code:
VBA Code:
Private Sub SubmitButton_Click()
Dim AllReq, AllAct As String
' This just gives me the row number in the database in which to record the info from the user form
If ThisWorkbook.Sheets("Production Numbers").Range("AT14").Value <> "" Then
rowNum = ThisWorkbook.Sheets("Production Numbers").Range("AT14").Value
Else: rowNum = ThisWorkbook.Sheets("Production Numbers").Range("AT16").Value
End If
' Verifies that all required fields are filled in before allowing the code to run
If Daily_Production_Results.RR390Act.Value = "" And Daily_Production_Results.SP390Act.Value = "" And Daily_Production_Results.RCAct.Value = "" And _
Daily_Production_Results.SCAct.Value = "" And Daily_Production_Results.FCAct.Value = "" And Daily_Production_Results.PEAct.Value = "" And _
Daily_Production_Results.WaveAct.Value = "" And Daily_Production_Results.WPAct.Value = "" And Daily_Production_Results.RCServiceAct.Value = "" And _
Daily_Production_Results.RCRemanAct.Value = "" And Daily_Production_Results.SCServiceAct.Value = "" And Daily_Production_Results.RCReworkAct.Value = "" And _
Daily_Production_Results.SCReworkAct.Value = "" Then
MsgBox "Please enter data before attempting to submit.", vbCritical, "Data Required!"
Exit Sub
End If
' Fills in empty spaces if no data was entered on certain fields
If Daily_Production_Results.RR390Act.Value = "" Then
Daily_Production_Results.RR390Act.Value = 0
End If
If Daily_Production_Results.RR400Act.Value = "" Then
Daily_Production_Results.RR400Act.Value = 0
End If
If Daily_Production_Results.SP390Act.Value = "" Then
Daily_Production_Results.SP390Act.Value = 0
End If
If Daily_Production_Results.SP400Act.Value = "" Then
Daily_Production_Results.SP400Act.Value = 0
End If
If Daily_Production_Results.RCAct.Value = "" Then
Daily_Production_Results.RCAct.Value = 0
End If
If Daily_Production_Results.SCAct.Value = "" Then
Daily_Production_Results.SCAct.Value = 0
End If
If Daily_Production_Results.RCSCSubAct.Value = "" Then
Daily_Production_Results.RCSCSubAct.Value = 0
End If
If Daily_Production_Results.FCAct.Value = "" Then
Daily_Production_Results.FCAct.Value = 0
End If
If Daily_Production_Results.PEAct.Value = "" Then
Daily_Production_Results.PEAct.Value = 0
End If
If Daily_Production_Results.WaveAct.Value = "" Then
Daily_Production_Results.WaveAct.Value = 0
End If
If Daily_Production_Results.WPAct.Value = "" Then
Daily_Production_Results.WPAct.Value = 0
End If
If Daily_Production_Results.RCServiceAct.Value = "" Then
Daily_Production_Results.RCServiceAct.Value = 0
End If
If Daily_Production_Results.RCRemanAct.Value = "" Then
Daily_Production_Results.RCRemanAct.Value = 0
End If
If Daily_Production_Results.SCServiceAct.Value = "" Then
Daily_Production_Results.SCServiceAct.Value = 0
End If
If Daily_Production_Results.RCReworkAct.Value = "" Then
Daily_Production_Results.RCReworkAct.Value = 0
End If
If Daily_Production_Results.SCReworkAct.Value = "" Then
Daily_Production_Results.SCReworkAct.Value = 0
End If
' used to do some calculations of totals for all fields entered
rrTReq = Daily_Production_Results.RR390Tar.Caption
spTReq = Daily_Production_Results.SP390Tar.Caption
rcTReq = Daily_Production_Results.RCTar.Caption
scTReq = Daily_Production_Results.SCTar.Caption
fcTReq = Daily_Production_Results.FCTar.Caption
peTReq = Daily_Production_Results.PETar.Caption
waveTReq = Daily_Production_Results.WaveTar.Caption
wpTReq = Daily_Production_Results.WPTar.Caption
rrTAct = Daily_Production_Results.RR390Act.Value
spTAct = Daily_Production_Results.SP390Act.Value
rcTAct = Daily_Production_Results.RCAct.Value
scTAct = Daily_Production_Results.SCAct.Value
fcTAct = Daily_Production_Results.FCAct.Value
peTAct = Daily_Production_Results.PEAct.Value
waveTAct = Daily_Production_Results.WaveAct.Value
wpTAct = Daily_Production_Results.WPAct.Value
rcservTAct = Daily_Production_Results.RCServiceAct.Value
rcremanTAct = Daily_Production_Results.RCRemanAct.Value
scservTAct = Daily_Production_Results.SCServiceAct.Value
AllReqO = CInt(rrTReq) + CInt(spTReq) + CInt(rcTReq) + CInt(scTReq) + CInt(fcTReq) + CInt(peTReq) + CInt(waveTReq) + CInt(wpTReq) + CInt(rcservTAct) + CInt(rcremanTAct) + CInt(scservTAct)
AllActO = CInt(rrTAct) + CInt(spTAct) + CInt(rcTAct) + CInt(scTAct) + CInt(fcTAct) + CInt(peTAct) + CInt(waveTAct) + CInt(wpTAct) + CInt(rcservTAct) + CInt(rcremanTAct) + CInt(scservTAct)
' trying to convert totals into decimal places
AllReq = Format(AllReqO, "##,##0.00")
AllAct = Format(AllActO, "##,##0.00")
' Begin transferring data to database on another workbook
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Unprotect "passcode"
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("A" & rowNum).Value = Daily_Production_Results.selDate.Caption
If selShift = 0.1 Then
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("B" & rowNum).Value = 3
ElseIf selShift = 0.2 Then
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("B" & rowNum).Value = 1
ElseIf selShift = 0.3 Then
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("B" & rowNum).Value = 2
ElseIf selShift = 0.4 Then
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("B" & rowNum).Value = "Sat"
ElseIf selShift = 0.5 Then
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("B" & rowNum).Value = "Sun"
End If
Workbooks("GEMBA BOARD DAILY PRODUCTION SHEET.xlsm").Worksheets("Production Targets").Range("C1").Value = Daily_Production_Results.dateShiftCombo.Caption
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("C" & rowNum).Value = Daily_Production_Results.dateShiftCombo.Caption
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("D" & rowNum).Value = Daily_Production_Results.RR390Tar.Caption
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("E" & rowNum).Value = Daily_Production_Results.RR390Act.Value
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("AJ" & rowNum).Value = Daily_Production_Results.RR400Tar.Caption
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("AK" & rowNum).Value = Daily_Production_Results.RR400Act.Value
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("F" & rowNum).Value = Daily_Production_Results.SP390Tar.Caption
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("G" & rowNum).Value = Daily_Production_Results.SP390Act.Value
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("AL" & rowNum).Value = Daily_Production_Results.SP400Tar.Caption
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("AM" & rowNum).Value = Daily_Production_Results.SP400Act.Value
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("AN" & rowNum).Value = Daily_Production_Results.RCSCSubTar.Caption
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("AO" & rowNum).Value = Daily_Production_Results.RCSCSubAct.Value
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("H" & rowNum).Value = Daily_Production_Results.RCTar.Caption
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("I" & rowNum).Value = Daily_Production_Results.RCAct.Value
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("J" & rowNum).Value = Daily_Production_Results.SCTar.Caption
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("K" & rowNum).Value = Daily_Production_Results.SCAct.Value
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("L" & rowNum).Value = Daily_Production_Results.FCTar.Caption
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("M" & rowNum).Value = Daily_Production_Results.FCAct.Value
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("N" & rowNum).Value = Daily_Production_Results.PETar.Caption
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("O" & rowNum).Value = Daily_Production_Results.PEAct.Value
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("P" & rowNum).Value = Daily_Production_Results.WaveTar.Caption
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("Q" & rowNum).Value = Daily_Production_Results.WaveAct.Value
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("R" & rowNum).Value = Daily_Production_Results.WPTar.Caption
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("S" & rowNum).Value = Daily_Production_Results.WPAct.Value
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("T" & rowNum).Value = AllReq
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("U" & rowNum).Value = AllAct
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("V" & rowNum).Value = Daily_Production_Results.RCRemanAct.Value
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("W" & rowNum).Value = Daily_Production_Results.RCRemanAct.Value
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("X" & rowNum).Value = Daily_Production_Results.RCServiceAct.Value
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("Y" & rowNum).Value = Daily_Production_Results.RCServiceAct.Value
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("Z" & rowNum).Value = Daily_Production_Results.SCServiceAct.Value
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("AA" & rowNum).Value = Daily_Production_Results.SCServiceAct.Value
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("AB" & rowNum).Value = Daily_Production_Results.RCReworkAct.Value
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("AC" & rowNum).Value = Daily_Production_Results.RCReworkAct.Value
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("AD" & rowNum).Value = Daily_Production_Results.SCReworkAct.Value
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("AE" & rowNum).Value = Daily_Production_Results.SCReworkAct.Value
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("AF" & rowNum).Value = CInt(rcTReq) + CInt(rcservTAct) + CInt(rcremanTAct)
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("AG" & rowNum).Value = CInt(rcTAct) + rcservTAct + rcremanTAct
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("AH" & rowNum).Value = CInt(scTReq) + scservTAct
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("AI" & rowNum).Value = CInt(scTAct) + scservTAct
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Range("AS" & rowNum).Value = "=row()"
Workbooks("Production Interruption Report.xlsm").Sheets("Daily Production").Protect "passcode", True, True
Workbooks("Production Interruption Report.xlsm").Save
' Copies over data for use in calculations - this is not what slows down the data transfer
'The following updates the production numbers
Workbooks("GEMBA BOARD DAILY PRODUCTION SHEET.xlsm").Worksheets("Production Numbers").Range("B1") = Format(Now(), "mm/dd/yyyy")
With ThisWorkbook.Worksheets("Production Numbers")
Workbooks(.Range("B11").Value).Worksheets(.Range("B12").Value).Range(.Range("B7").Value & ":" & .Range("B8").Value).Copy
Workbooks("GEMBA BOARD DAILY PRODUCTION SHEET.xlsm").Worksheets("Production Numbers").Range("A15").PasteSpecial xlPasteValues
Application.CutCopyMode = False
End With
Unload Me
Application.ScreenUpdating = False
Application.ScreenUpdating = True
'Application.DisplayAlerts = False
'Workbooks("Production Interruption Report.xlsm").Close
'Application.DisplayAlerts = True
Workbooks("GEMBA BOARD DAILY PRODUCTION SHEET.xlsm").Save
End Sub