I have received a workbook that populates data from an SQL database. Once the "Master" worksheet is populated if the user right clicks any row greater or equal to row 3 and column A a more detailed view of the "Job" selected is displayed in a user form. In this form a "Total Actual Hours" column is displayed and populated along with some other information. I would like to have this "Total Actual Hours" value displayed in the "Master" sheet as well to provide a quicker reference for the users. This workbook contains multiple user forms, modules and codes so if I have missed some or additional information is needed please let me know and I will try to have them added.
VBA Code:
Private Sub ExportSpecial()
Dim tmpRS As ADODB.Recordset
Dim tmpST As String
Dim tmpI As Long
tmpI = 100
Dim tmpPr As Variant 'Priority
Dim tmpSD As Variant 'Start Date
Dim tmpED As Variant 'End Date
Dim tmpDL As Variant 'Days Late
Dim tmpWC As Variant 'Work Code
Dim tmpN As Variant 'Notes
Dim tmpAH As Variant 'Actual Hours ADDED BY: TCII
tmpST = txtSpecial
' objM.Range("AV4").Value = tmpST
Set tmpRS = ExecSQL(tmpST)
If tmpRS.RecordCount > 0 Then
While Not tmpRS.EOF
objM.Range(Column("JobNo", objM) & intR).Value = Trim(tmpRS("JobNo").Value)
tmpPr = ImportPriority(tmpRS("Priority").Value)
objM.Range(Column("Priority", objM) & intR).Value = tmpPr
objM.Range(Column("PONum", objM) & intR).Value = Trim(tmpRS("PONum").Value)
objM.Range(Column("CustCode", objM) & intR).Value = Trim(tmpRS("CustCode").Value)
objM.Range(Column("PartNo", objM) & intR).Value = UCase(Trim(tmpRS("PartNo").Value))
objM.Range(Column("PartDesc", objM) & intR).Value = UCase(Replace(Trim(tmpRS("PartDesc").Value), vbLf, ""))
objM.Range(Column("ProdCode", objM) & intR).Value = Trim(tmpRS("ProdCode").Value)
objM.Range(Column("Type", objM) & intR).Value = CalcType(tmpRS)
If Not IsNull(tmpRS("OrderDate").Value) Then objM.Range(Column("OrderDate", objM) & intR).Value = tmpRS("OrderDate").Value
objM.Range(Column("Jobs", objM) & intR).Value = tmpRS("Jobs").Value
objM.Range(Column("Qty", objM) & intR).Value = tmpRS("Qty").Value
objM.Range(Column("SetupTime", objM) & intR).Value = tmpRS("SetupTime").Value
objM.Range(Column("SetupUnit", objM) & intR).Value = Trim(tmpRS("SetupUnit").Value)
If VerifyDate(tmpRS("StartDate").Value) And VerifyDate(tmpRS("EndDate").Value) Then
tmpSD = DateValue(tmpRS("StartDate").Value)
objM.Range(Column("StartDate", objM) & intR).Value = tmpSD
tmpED = DateValue(tmpRS("EndDate").Value)
objM.Range(Column("EndDate", objM) & intR).Value = tmpED
objM.Range(Column("Days", objM) & intR).Value = CalcWork(tmpSD, tmpED)
tmpDL = CalcWork(tmpSD, Now())
If tmpDL > 0 Then
objM.Range(Column("DaysLate", objM) & intR).Value = tmpDL
objM.Range(Column("DaysLate", objM) & intR).Interior.Color = 255
End If
Else
If VerifyDate(tmpRS("StartDate").Value) Then objM.Range(Column("StartDate", objM) & intR).Value = DateValue(tmpRS("StartDate").Value) _
Else objM.Range(Column("StartDate", objM) & intR).Value = "ERROR"
If VerifyDate(tmpRS("EndDate").Value) Then objM.Range(Column("EndDate", objM) & intR).Value = DateValue(tmpRS("EndDate").Value) _
Else objM.Range(Column("EndDate", objM) & intR).Value = "ERROR"
objM.Range(Column("Days", objM) & intR).Value = "ERROR"
intE = intE + 1
End If
tmpWC = tmpRS("WorkCode").Value
If Not IsNull(tmpRS("ONotes").Value) Then
tmpN = UCase(Trim(tmpRS("ONotes").Value))
Else
tmpN = ""
End If
If Not IsNull(tmpRS("JNotes").Value) Then
If tmpN <> "" Then tmpN = tmpN & " / "
tmpN = UCase(Trim(tmpRS("OpNotes").Value))
End If
tmpN = Replace(tmpN, "~", "'")
If Not IsNull(tmpRS("Scheduled").Value) Then _
objM.Range(Column("Schedule", objM) & intR).Value = tmpRS("Scheduled").Value
If Not IsNull(tmpRS("Quality").Value) Then _
objM.Range(Column("Quality", objM) & intR).Value = tmpRS("Quality").Value
If Not IsNull(tmpRS("Printed").Value) Then _
objM.Range(Column("Printed", objM) & intR).Value = tmpRS("Printed").Value
If intR > tmpI Then
Call UpdateStatusBar("PROCESSING - " & tmpI)
tmpI = tmpI + 100
' Set tmpRS = Nothing
' Exit Sub
End If
If tmpWC <> "" And tmpN = "" Then
tmpN = tmpWC
ElseIf tmpWC <> "" And tmpN <> "" Then
tmpN = tmpWC & " // " & tmpN
End If
objM.Range(Column("Notes", objM) & intR).Value = tmpN
intR = intR + 1
tmpRS.MoveNext
Wend
Else
MsgBox "No Jobs Found", vbExclamation
intR = 0
Set tmpRS = Nothing
Call ProtectSheet(objM)
Call ProtectSheet(objR)
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.StatusBar = False
Exit Sub
End If
Set tmpRS = Nothing
End Sub
VBA Code:
Public Sub SchedDetail(ByVal tmpTarget As Range, ByVal tmpJobName As String, ByVal tmpStepName As String, Optional ByVal tmpPage As Integer = 0)
Dim tmpJob As String
Dim tmpStep As String
Set objTarget = tmpTarget
txtJobName = tmpJobName
txtStepName = tmpStepName
Set objS = tmpTarget.Worksheet
intR = tmpTarget.Row
tmpJob = objS.Range(Column(tmpJobName, objS) & intR).Text
tmpStep = objS.Range(Column(tmpStepName, objS) & intR).Text
If tmpStep = "" Then tmpStep = "00"
Call ConnectSQL
Call ImportOrder(frmSchedDetail, frmSchedDetail.objOrder, tmpJob)
Call ImportJob(frmSchedDetail, frmSchedDetail.objJob, tmpJob, tmpStep)
Call ImportRequired(frmSchedDetail.objRequired, tmpJob)
Call ImportIssued(frmSchedDetail.objIssued, tmpJob)
If ImportNC(frmSchedDetail.objNC, tmpJob) > 0 Then frmSchedDetail.mpSchedDetail.Pages(3).Visible = True
Call CloseSQL
If ImportHours(frmSchedDetail.objHours, tmpJob, tmpStep) > 0 Then frmSchedDetail.mpSchedDetail.Pages(6).Visible = True
'Call ImportWeekMach(frmSchedDetail, frmSchedDetail.objMach, tmpJob, tmpStep)
Call ImportMachHist(frmSchedDetail.objMach, tmpJob, tmpStep)
Call ImportJobs(frmSchedDetail.objJobs, tmpJob, tmpStep)
frmSchedDetail.mpSchedDetail.value = tmpPage
frmSchedDetail.Show
End Sub
VBA Code:
Public Function ImportJob(ByVal tmpForm As UserForm, ByVal tmpList As ListView, _
ByVal tmpJob As String, Optional ByVal tmpStep As String = "00", _
Optional ByRef tmpComp As String = "", _
Optional ByRef tmpWork As String = "", _
Optional ByRef tmpActual As Date = "1/1/1900", _
Optional ByRef tmpScrap As Integer = 0, _
Optional ByRef tmpDisp As Integer = 0, _
Optional ByRef tmpNotes As String = "") As String
Dim tmpRS As ADODB.Recordset
Dim tmpR As Integer
Dim tmpSt As String
Dim tmpDC As Integer 'Color
Dim tmpDL As Integer 'Days Late
Dim tmpS As Integer 'Scrap
Dim tmpTC As Integer 'Temp Color
Dim tmpTL As Integer 'Temp Days Late
Dim tmpWC As String 'Workcenter
Dim tmpOC As String 'Operation Code
Dim tmpSa As String 'Status
Dim tmpSe As String 'Step
Call ClearListView(tmpList)
tmpSt = "select D.PartNo, D.Priority, D.PartDesc, D.QtyOrdered, D.QtyToMake, D.WorkCode JobType, D.JobNotes, case when " & _
"D.Status = 'Closed' or R.ActualEndDate is not null then 'X' when R.ActualStartDate is not null then 'IP' " & _
"else '' end Status, R.StepNo, R.WorkOrVend, R.WorkCntr, R.OperCode OpCode, R.VendCode, R.SetupTime, R.TimeUnit " & _
"SetupUnit, R.Descrip, R.ActualPcsGood, R.ActualPcsScrap, R.EstimStartDate, R.EstimEndDate, R.TotActHrs, " & _
"R.TotActHrs, R.TotEstHrs, R.ActualEndDate, MRB.Disposition, MRB.Notes " & _
"from OrderDet D " & _
"left join OrderRouting R on R.JobNo = D.JobNo " & _
"left join VendCode V on V.VendCode = R.VendCode " & _
"left join ZZZ_MRB MRB on MRB.JobNo = D.JobNo and MRB.StepNo = R.StepNo " & _
"where D.JobNo = 'JOBNO' " & _
"order by R.StepNo"
tmpSt = Replace(tmpSt, "JOBNO", tmpJob)
Set tmpRS = ExecSQL(tmpSt)
tmpDC = 0
tmpDL = -999
tmpR = 0
tmpComp = ""
tmpWork = ""
tmpActual = Now()
tmpScrap = 0
tmpDisp = 0
tmpNotes = ""
If tmpRS.RecordCount > 0 Then
ImportJob = Trim(tmpRS("PartNo").value)
tmpForm.txtJobNo.Text = tmpJob
tmpForm.txtPriority.Text = ImportPriority(tmpRS("Priority").value)
tmpForm.txtPartNo.Text = UCase(Trim(tmpRS("PartNo").value))
tmpForm.txtPartDesc.Text = UCase(Trim(tmpRS("PartDesc").value))
tmpForm.txtOrderQty.Text = Trim(tmpRS("QtyOrdered").value)
tmpForm.txtMakeQty.Text = Trim(tmpRS("QtyToMake").value)
tmpForm.txtJobType.Text = Trim(tmpRS("JobType").value)
tmpForm.txtJobNotes.Text = UCase(Trim(tmpRS("JobNotes").value))
While Not tmpRS.EOF
Call AddRowListView(tmpList)
tmpTC = -1
tmpSa = tmpRS("Status").value
tmpSe = Trim(tmpRS("StepNo").value)
If tmpSa = "X" And tmpSe = tmpStep Then
Call WriteListView(tmpList, tmpR, 1, "X>")
Call ColorListView(tmpList, tmpR, &HFF8080) 'Light Blue
tmpComp = "X"
If Not IsNull(tmpRS("WorkCntr")) Then _
tmpWork = Trim(tmpRS("WorkCntr").value)
If Not IsNull(tmpRS("ActualEndDate")) Then _
tmpActual = tmpRS("ActualEndDate").value
If Not IsNull(tmpRS("ActualPcsScrap")) Then _
tmpScrap = tmpRS("ActualPcsScrap").value
If Not IsNull(tmpRS("Disposition")) Then _
tmpDisp = tmpRS("Disposition").value
If Not IsNull(tmpRS("Notes")) Then _
tmpNotes = Trim(tmpRS("Notes").value)
ElseIf tmpSa = "X" Then
Call WriteListView(tmpList, tmpR, 1, "X")
Call ColorListView(tmpList, tmpR, &H80000011) 'Grey
ElseIf tmpSe = tmpStep Then
Call WriteListView(tmpList, tmpR, 1, ">>")
Call ColorListView(tmpList, tmpR, &HC00000) 'Blue
If Not IsNull(tmpRS("WorkCntr")) Then _
tmpWork = Trim(tmpRS("WorkCntr").value)
If Not IsNull(tmpRS("ActualEndDate")) Then _
tmpActual = tmpRS("ActualEndDate").value
If Not IsNull(tmpRS("ActualPcsScrap")) Then _
tmpScrap = tmpRS("ActualPcsScrap").value
If Not IsNull(tmpRS("Disposition")) Then _
tmpDisp = tmpRS("Disposition").value
If Not IsNull(tmpRS("Notes")) Then _
tmpNotes = Trim(tmpRS("Notes").value)
Else
Call ColorListView(tmpList, tmpR, &H80000012) 'Black
End If
Call WriteListView(tmpList, tmpR, 2, tmpSe)
If tmpRS("WorkOrVend").value = 0 Then
tmpWC = Trim(tmpRS("WorkCntr").value)
tmpOC = Trim(tmpRS("OpCode").value)
Else
tmpWC = "OUTSOURCE"
tmpOC = Trim(tmpRS("VendCode").value)
End If
Call WriteListView(tmpList, tmpR, 3, tmpWC)
If tmpOC = "SHIP INV" And tmpRS("SetupUnit").value <> "M" And tmpRS("SetupTime").value > 0 Then
Call WriteListView(tmpList, tmpR, 4, "SHIP INV**")
Else
Call WriteListView(tmpList, tmpR, 4, tmpOC)
End If
Call WriteListView(tmpList, tmpR, 5, ConvertDesc(tmpRS("Descrip").value))
Call WriteListView(tmpList, tmpR, 6, tmpRS("Descrip").value)
If tmpSa <> "" Then
Call WriteListView(tmpList, tmpR, 7, tmpRS("ActualPcsGood").value)
tmpS = tmpRS("ActualPcsScrap").value
If Not IsNull(tmpRS("Disposition")) Then
If tmpRS("Disposition").value > 0 Then
Call WriteListView(tmpList, tmpR, 8, tmpS & "*")
Else
Call WriteListView(tmpList, tmpR, 8, tmpS)
End If
Else
Call WriteListView(tmpList, tmpR, 8, tmpS)
End If
If tmpS > 0 Then Call BoldListViewItem(tmpList, tmpR, 8, True)
End If
If Not IsNull(tmpRS("EstimStartDate")) Then
Call WriteListView(tmpList, tmpR, 9, Format(tmpRS("EstimStartDate").value, "m/d"))
If tmpSa <> "X" Then
If CDate(tmpRS("EstimStartDate").value) < CDate(Now()) Then
If tmpWC <> "MATLOG" And tmpDC = 0 Then tmpDC = 1
tmpTC = 1
Else
tmpTC = 0
End If
End If
End If
If Not IsNull(tmpRS("EstimEndDate")) Then
Call WriteListView(tmpList, tmpR, 10, Format(tmpRS("EstimEndDate").value, "m/d"))
If tmpSa <> "X" Then
tmpTL = CalcWork(tmpRS("EstimEndDate").value, Now()) - 1
If tmpWC <> "MATLOG" And tmpTL > tmpDL Then tmpDL = tmpTL
End If
End If
If tmpTL > 5 Then
Call WriteListView(tmpList, tmpR, 11, tmpTL)
Call ColorJob(tmpList, tmpR, &H40C0&) 'Orange
ElseIf tmpTL > 0 Then
Call WriteListView(tmpList, tmpR, 11, tmpTL)
Call ColorJob(tmpList, tmpR, &HFF&) 'Red
ElseIf tmpTC = 1 Then
Call ColorJob(tmpList, tmpR, &HC0C0&) 'Yellow
ElseIf tmpTC = 0 Then
Call ColorJob(tmpList, tmpR, &HC000&) 'Green
End If
Call WriteListView(tmpList, tmpR, 12, Format(tmpRS("TotEstHrs").value, "0.00"))
If tmpOC = "SHIP INV" And tmpRS("SetupUnit").value <> "M" And tmpRS("SetupTime").value > 0 Then _
Call BoldListViewItem(tmpList, tmpR, 12, True)
If tmpSa <> "" Then
Call WriteListView(tmpList, tmpR, 13, Format(tmpRS("TotActHrs").value, "0.00"))
If Not IsNull(tmpRS("ActualEndDate")) Then _
Call WriteListView(tmpList, tmpR, 14, Format(tmpRS("ActualEndDate").value, "m/d"))
End If
If tmpSe = tmpStep Then
tmpForm.txtOpDesc.Text = UCase(tmpRS("Descrip").value)
tmpForm.mpJobDetail.Pages(0).Visible = True
tmpForm.mpJobDetail.value = 0
End If
tmpR = tmpR + 1
tmpRS.MoveNext
Wend
Else
MsgBox "ERROR: No Operations (" & tmpJob & ")", vbCritical
End If
If tmpDL > 5 Then
frmSchedDetail.txtDaysLate.BackColor = &H80FF& 'Orange
frmSchedDetail.txtDaysLate.Text = tmpDL
ElseIf tmpDL > 0 Then
frmSchedDetail.txtDaysLate.BackColor = &HFF& 'Red
frmSchedDetail.txtDaysLate.Text = tmpDL
ElseIf tmpDC = 1 Then
frmSchedDetail.txtDaysLate.BackColor = &H80FFFF 'Yellow
frmSchedDetail.txtDaysLate.Text = 0
Else
frmSchedDetail.txtDaysLate.BackColor = &H80FF80 'Green
frmSchedDetail.txtDaysLate.Text = 0
End If
Set tmpRS = Nothing
End Function