I have the following module that should update a recordsets Bseq field. It works some of the time, but it will occasionally not increase the Bseq as needed. I don't know if the line of code mCurBSeq = (mCurCounter Mod 15) + 1 is in the wrong place or improperly used.
Function Updategjw()
Dim dbsEngraving00 As Database
Dim rstEngraving As Recordset
Dim tdfEngraving As TableDef
Dim mCurBSeq, mCurBatch, mCurCounter, mCurSeq As Long
Dim mCurTruck
Dim mPrevTruck
Dim mPrevBseq, mPrevBatch, mPrevCounter, mPrevSeq As Long
Dim mBSeq, mBatch, mCounter As Integer
Dim RecCount As Integer
mBSeq = 1
mBatch = 100
mCounter = 0
Set dbsEngraving00 = CurrentDb
Set tdfEngraving = dbsEngraving00.CreateTableDef("EngravingTableDef")
Set rstEngraving = dbsEngraving00.OpenRecordset("Engraving", dbOpenTable)
rstEngraving.Index = "JSP"
With rstEngraving
' Populate Recordset.
.MoveLast
.MoveFirst
'Set starting BSeq, Batch and Counter
.Edit
!BSeq = mBSeq
!Batch = mBatch
!Counter = mCounter
.Update
'Update variables
mPrevBseq = !BSeq
mPrevBatch = !Batch
mPrevCounter = !Counter
mPrevTruck = !JobPkTk
mPrevSeq = !SeqNo
RecCount = 1
.MoveNext
Do Until .EOF
mCurBSeq = !BSeq
mCurBatch = !Batch
mCurCounter = !Counter
mCurTruck = !JobPkTk
mCurSeq = !SeqNo
If mPrevTruck <> !JobPkTk Then
mCurBSeq = 1
If mPrevBseq = 15 And mCurBSeq = 1 Then
mCurBatch = mPrevBatch + 1
mCurCounter = 0
ElseIf mCurTruck <> mPrevTruck Then
mCurBatch = mPrevBatch + 1
If mCurBatch <> mPrevBatch Then
mCurCounter = 0
ElseIf mCurSeq <> mPrevSeq Then
mCurCounter = mPrevCounter + 1
Else
mCurCounter = mPrevCounter
End If
Else
mCurBatch = mPrevBatch
If mCurBatch <> mPrevBatch Then
mCurCounter = 0
ElseIf mCurSeq <> mPrevSeq Then
mCurCounter = mPrevCounter + 1
Else
mCurCounter = mPrevCounter
End If
End If
Else
If mCurBatch <> mPrevBatch Then
mCurCounter = 0
ElseIf mCurSeq <> mPrevSeq Then
mCurCounter = mPrevCounter + 1
Else
mCurCounter = mPrevCounter
End If
mCurBSeq = (mCurCounter Mod 15) + 1
If mPrevBseq = 15 And mCurBSeq = 1 Then
mCurBatch = mPrevBatch + 1
mCurCounter = 0
ElseIf mCurTruck <> mPrevTruck Then
mCurBatch = mPrevBatch + 1
Else
mCurBatch = mPrevBatch
End If
End If
.Edit
!BSeq = mCurBSeq
!Batch = mCurBatch
!Counter = mCurCounter
.Update
.MoveNext
mPrevSeq = mCurSeq
mPrevTruck = mCurTruck
mPrevBseq = mCurBSeq
mPrevBatch = mCurBatch
mPrevCounter = mCurCounter
RecCount = RecCount + 1
Loop
End With
dbsEngraving00.Close
MsgBox "Update Complete on " & RecCount & " records."
End Function
Thanks for the help.
Greg
Function Updategjw()
Dim dbsEngraving00 As Database
Dim rstEngraving As Recordset
Dim tdfEngraving As TableDef
Dim mCurBSeq, mCurBatch, mCurCounter, mCurSeq As Long
Dim mCurTruck
Dim mPrevTruck
Dim mPrevBseq, mPrevBatch, mPrevCounter, mPrevSeq As Long
Dim mBSeq, mBatch, mCounter As Integer
Dim RecCount As Integer
mBSeq = 1
mBatch = 100
mCounter = 0
Set dbsEngraving00 = CurrentDb
Set tdfEngraving = dbsEngraving00.CreateTableDef("EngravingTableDef")
Set rstEngraving = dbsEngraving00.OpenRecordset("Engraving", dbOpenTable)
rstEngraving.Index = "JSP"
With rstEngraving
' Populate Recordset.
.MoveLast
.MoveFirst
'Set starting BSeq, Batch and Counter
.Edit
!BSeq = mBSeq
!Batch = mBatch
!Counter = mCounter
.Update
'Update variables
mPrevBseq = !BSeq
mPrevBatch = !Batch
mPrevCounter = !Counter
mPrevTruck = !JobPkTk
mPrevSeq = !SeqNo
RecCount = 1
.MoveNext
Do Until .EOF
mCurBSeq = !BSeq
mCurBatch = !Batch
mCurCounter = !Counter
mCurTruck = !JobPkTk
mCurSeq = !SeqNo
If mPrevTruck <> !JobPkTk Then
mCurBSeq = 1
If mPrevBseq = 15 And mCurBSeq = 1 Then
mCurBatch = mPrevBatch + 1
mCurCounter = 0
ElseIf mCurTruck <> mPrevTruck Then
mCurBatch = mPrevBatch + 1
If mCurBatch <> mPrevBatch Then
mCurCounter = 0
ElseIf mCurSeq <> mPrevSeq Then
mCurCounter = mPrevCounter + 1
Else
mCurCounter = mPrevCounter
End If
Else
mCurBatch = mPrevBatch
If mCurBatch <> mPrevBatch Then
mCurCounter = 0
ElseIf mCurSeq <> mPrevSeq Then
mCurCounter = mPrevCounter + 1
Else
mCurCounter = mPrevCounter
End If
End If
Else
If mCurBatch <> mPrevBatch Then
mCurCounter = 0
ElseIf mCurSeq <> mPrevSeq Then
mCurCounter = mPrevCounter + 1
Else
mCurCounter = mPrevCounter
End If
mCurBSeq = (mCurCounter Mod 15) + 1
If mPrevBseq = 15 And mCurBSeq = 1 Then
mCurBatch = mPrevBatch + 1
mCurCounter = 0
ElseIf mCurTruck <> mPrevTruck Then
mCurBatch = mPrevBatch + 1
Else
mCurBatch = mPrevBatch
End If
End If
.Edit
!BSeq = mCurBSeq
!Batch = mCurBatch
!Counter = mCurCounter
.Update
.MoveNext
mPrevSeq = mCurSeq
mPrevTruck = mCurTruck
mPrevBseq = mCurBSeq
mPrevBatch = mCurBatch
mPrevCounter = mCurCounter
RecCount = RecCount + 1
Loop
End With
dbsEngraving00.Close
MsgBox "Update Complete on " & RecCount & " records."
End Function
Thanks for the help.
Greg