Dim rs As DAO.Recordset
Dim Crs As DAO.Recordset
Dim wrk As DAO.Workspace
Dim SID As Long 'Variable for SingleID
Dim r As Long 'variable for ReelID
Dim ID As Long 'variable for ticketID
Dim CurL As Long 'variable for current length
Dim CutL As Long 'variable for cut length
Dim CutN As Long 'variable for number of cuts
Dim nCut As Long 'variable for total cut length
Dim strsql As String
On Error GoTo ErrorHandler
ID = [Forms]![frmWireRoom]![TicketID]
'get recordset from singles table
Set wrk = DBEngine.Workspaces(0)
Set rs = CurrentDb.OpenRecordset("SELECT * FROM tblSingleCut WHERE TicketID = " & ID & "")
With rs
wrk.BeginTrans
Do While Not .EOF
SID = ![SingleID]
r = ![WireReelID]
CutL = ![CutLength]
CutN = ![CutNum]
If IsNull(CutN) Then
nCut = CutL
End If
nCut = CutL * CutN
'set second recordset to update reels
Set Crs = CurrentDb.OpenRecordset("SELECT * FROM tblWireRoom WHERE [ReelID] = " & r & "")
With Crs
If ![ReelID] = r Then
Crs.Edit
CurL = ![CurrentLength]
Crs!CurrentLength = CurL - nCut
Crs.Update
End If
End With
With rs
If ![SingleID] = SID Then
rs.Edit
![SingleComplete] = True
rs.Update
End If
End With
strsql = "INSERT INTO tblCutLog ( CutReelID, StartingLength, CutLength, EndLength, TicketID) "
strsql = strsql & "VALUES (" & r & ", " & CurL & ", " & nCut & ", " & CurL - nCut & ", " & ID & ");"
CurrentDb.Execute strsql, dbFailOnError
.MoveNext
Loop
End With
wrk.CommitTrans
ErrorHandler:
Select Case Err.Number
Case 3317
MsgBox "One of the choosen source(s) has insufficient length. Please choose a different source. Operation has been canacelled and no changes have been made", vbOKOnly, "Error"
wrk.Rollback
Exit Sub
End Select