Looping to find the maximum value of a variable

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.
 
G

George Nicholson

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
 
P

PC Datasheet

Dim Maxrecord_qty As Long
Maxrecord_qty = NewRecord_qty
IF NewRecord_qty > Maxrecord_qty THEN
Maxrecord_qty = Newrecord_qty
end if
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top