On Error GoTo ErrHandler
vTicketID = [Forms]![frmWireRoom]![TicketID]
Set wrk = DBEngine.Workspaces(0)
Set DB = CurrentDb()
wrk.BeginTrans
Set MultiRS = DB.OpenRecordset("SELECT MultiID, WireReelID, CutLength, CutNum, MultiComplete FROM tblMultiConductorCut " _
& "WHERE TicketID = " & vTicketID & " AND MultiComplete = False")
Set LogRS= DB.OpenRecordset("SELECT * FROM tblCutLog")
Do While Not MultiRS.EOF
vMultiID = MultiRS("MultiID")
vReelID = MultiRS("WireReelID")
vCutLength = MultiRS"CutLength")
vCutNum = MultiRS("CutNum")
'If number of cuts is null then set total to the cut length else multiply cut length times number of cuts
If IsNull(vCutNum) Then
TotalLength = vCutLength
Else
TotalLength = vCutLength * vCutNum
End If
Set WireRS = DB.OpenRecordset("SELECT ReelID, CurrentLength FROM tblWireRoom WHERE [ReelID] = " & vReelID & "")
WireRS.Edit
vCurrentLength = WireRS("CurrentLength")
WireRS("CurrentLength") = vCurrentLength - TotalLength
WireRS.Update
WireRS.Close
MultiRS.Edit
MultiRS("MultiComplete") = True
MultiRS.Update
LogRS.AddNew
LogRS("CutReelID").Value = vReelID
LogRS("StartingLength").Value = vCurrentLength
LogRS("CutLength").Value = TotalLength
LogRS("EndLength").Value = vCurrentLength - TotalLength
LogRS("TicketID").Value = vTicketID
LogRS.Update
MultiRS.MoveNext
Loop
MultiRS.Close
LogRS.Close
wrk.CommitTrans
NoError = True
Exit Sub
ErrHandler:
NoError = False
Select Case Err.Number
Case 3317
'one of the choosen reels did not have enough length
MsgBox "One of the choosen source(s) has insufficient length for Multi-Conductor's. Please choose a different source. Operation has been canacelled and no changes have been made", vbOKOnly, "Error"
wrk.Rollback
NoError = False
Exit Sub
Case Else
MsgBox Err.Description, vbOKOnly, Err.Number
wrk.Rollback
End Select