Function ProductionInputSave()
Dim intProductionID As Integer
Dim rsProductionExist As ADODB.Recordset
Dim rsProduction As ADODB.Recordset
'''''''''''''Dummy Proof
If txtHouseCountDetail.Enabled = True And txtHouseCountDetail = "" Then msgFunctionCount = MsgBox("You did not have any units for the House Count function."): GoTo ErrorEnd
If txtMDUCountDetail.Enabled = True And txtMDUCountDetail = "" Then msgFunctionCount = MsgBox("You did not have any units for the MDU Count function."): GoTo ErrorEnd
If txtCommercialCountDetail.Enabled = True And txtCommercialCountDetail = "" Then msgFunctionCount = MsgBox("You did not have any units for the Commercial Count function."): GoTo ErrorEnd
IntX = 1
For IntX = IntX To 13
If Me.Controls(("cboFunctionType") + Format$(IntX)) <> "" And Me.Controls(("txtFunctionDetail") + Format$(IntX)) = "" Then msgFunctionCount = MsgBox("You did not have any units for the " & cboFunctionType1.Column(2) & " function."): GoTo ErrorEnd
Next IntX
If cboFunctionSel = "" Then MsgBox "Please select a function.": GoTo DupeEnd
''''''''''''''
Set rsProductionExist = New ADODB.Recordset
Set rsProduction = New ADODB.Recordset
'Resetting variables
If txtAerial = "" Then Call ResetTextBox(txtAerial)
If txtUnderground = "" Then Call ResetTextBox(txtUnderground)
If txtUnits = "" Then Call ResetTextBox(txtUnit)
If IsNull(chkSetup) = True Or chkSetup = False Then
With Me.chkSetup
.Enabled = True
.Value = 0
.Enabled = False
End With
End If
'Add Line of Production
intProductionID = NewProductionLine()
DoCmd.OpenForm "frmTrackingData", acNormal, , , , acDialog, intProductionID
With rsProductionExist
.ActiveConnection = CurrentProject.Connection
.Source = "SELECT ProductionID FROM tblProductionTracking WHERE ProductionID = " & intProductionID
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Open
If .EOF = True Then msgTracking = MsgBox("You did not save a Function Track for this map. Are you sure you want to continue?", vbYesNo)
If .EOF = True And msgTracking = vbYes Then GoTo DeleteProductionLineItem
If msgTracking = vbNo Then GoTo ErrorEnd
.Update
.Close
End With
If FunctionTrackExists(Forms("frmProductionInput").Controls("cboFunctionSel"), ERRORTRACKING) = True Then
DeleteProductionLineItem:
With rsProduction
.ActiveConnection = CurrentProject.Connection
.Source = "SELECT * FROM tblProductionInput WHERE ProductionID = " & intProductionID
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Open
.Delete
.Update
.Close
End With
GoTo ErrorEnd
End If
'Add detail lines of production to tblProductionInputDetail
Call NewProductionLineDetail(intProductionID, "Aerial", Nz(txtAerial.Value, 0))
Call NewProductionLineDetail(intProductionID, "Underground", Nz(txtUnderground.Value, 0))
Call NewProductionLineDetail(intProductionID, "Unit", Nz(txtUnit.Value, 0))
If chkSetup = False Or chkSetup = 0 Then Call NewProductionLineDetail(intProductionID, "Setup", 1)
Call AddSubfunctionData(intProductionID)
'Tidy up Form
With Me
.chkSetup = False
.txtAerial = Null
.txtUnderground = Null
.txtUnit = Null
.txtComments = Null
.txtDate.SetFocus
.fmeStatus = 1
.txtHouseCountDetail = Null
.txtMDUCountDetail = Null
.txtCommercialCountDetail = Null
For IntX = 1 To 13
.Controls("txtFunctionDetail" + Format$(IntX)) = Null
.Controls("cboFunctionType" + Format$(IntX)) = Null
Next IntX
.ProductionList.Requery
End With
DupeEnd:
ErrorEnd:
txtAerial.Enabled = True
txtUnderground.Enabled = True
txtUnit.Enabled = True
chkSetup.Enabled = True
If FunctionTypeSearch(cboFunctionSel, "Aerial") = False Then txtAerial.Enabled = False
If FunctionTypeSearch(cboFunctionSel, "Underground") = False Then txtUnderground.Enabled = False
If FunctionTypeSearch(cboFunctionSel, "Unit") = False Then txtUnit.Enabled = False
If FunctionTypeSearch(cboFunctionSel, "Setup") = False Then chkSetup.Enabled = False
End Function