Looping to find the maximum value of a variable

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

I have a looping statement that stores "record_Qty" to a long variable.
Each time the loop cycles it stores the record quantity to "record_qty" .
What I want is a way to show the largest number that the record_qty has been
during the looping process. If I use:

IF NewRecord_qty > record_qty THEN
record_qty = Newrecord_qty
end if

I only get the greater of the last two records.

What is the procedure to retrieve the largest record_qty value after the
loop is complete.
 
What is the procedure to retrieve the largest record_qty value after the
loop is complete.

If the value is in a Table then you can use the DMax aggregate function, but
why not capture it during the loop?

For Each.......
.....yada, yada
If MaxRecQty < record_qty Then
MaxRecQty = record_qty
End If
Next

MsgBox "The largest record_qty is " & MaxRecQty

HTH,
George
 
Dim Maxrecord_qty As Long
Maxrecord_qty = NewRecord_qty
IF NewRecord_qty > Maxrecord_qty THEN
Maxrecord_qty = Newrecord_qty
end if
 
Back
Top