Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mod operator portion of code not consistent

Status
Not open for further replies.

razchip

Technical User
Feb 2, 2001
133
US
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
 
What is the intention of the line of code?

Perhaps you mean...

Code:
mCurBSeq = ([red]RecCount[/red] Mod 15) + 1

Hard to say without knowing what it should do but the above is an obvious guess.
 
What I'm trying to do is increase a field called mCurBSeq by 1. If mCurCounter =3, then mCurBSeq shouls be 4. For some reason, the line in question doesn't always return the new value.

I will give your suggestion a try.

Thanks,

Thanks for the help.
Greg
 
razchip said:
What I'm trying to do is increase a field called mCurBSeq by 1. If mCurCounter =3, then mCurBSeq shouls be 4

Then wouldn't it simply be:

mCurBSeq = mCurCounter + 1

 
I'll try that also, sometimes I try to out think the program and forget the easy approach, thanks.

Thanks for the help.
Greg
 
A good approach to such problems is to stop writing code, and just write out in plain language what it is you want to do. Usually, this leads to one of two things:

1. You have clear pseudo-code that can be directly translated to real code
2. You realize you don't know exactly what it is you need to accomplish, which means you need to reassess what your requirements really are
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top