Dear Modest,
Imagine the following table with the it's data.
Quantity
1.56
2.09
0.99
0.33
4.87
I want the code to do the following precedures:
- Start with the 1stField (1.56). Count the int of 1.56 and replace the result with the field and keep the remain fraction into account and add it to the next field ==> int(1.56) = 1, remained fraction 0.56. The same job for the next fields with looping. Therefore, the code does like this:
Quantity
1 '(0.56) into account to be added to next field => 0.56+2.09=2.65
2 '(0.65) into account to be added to next field => 0.65+0.99=1.64
1 '(0.64) into account to be added to next field => 0.64+0.33=0.97
0 '(0.97) into account to be added to next field => 0.97+4.87=5.84
5 '(0.84) into account to be added to next field => etc.
The source code to be modified is below:
Dim iTotal As Double
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDB
Set rs = db.OpenRecordset("table name",dbOpenDynaset)
rs.Movelast: rs.Movefirst
iTotal = 0
Do Until rs.EOF
With rs
If .Fields("Quantity") < 1 Then
If iTotal + .Fields("Quantity") < 1 Then
iTotal = iTotal + .Fields("Quantity")
.Edit
.Fields("Quantity") = 0
.Update
Else
iTotal = iTotal + .Fields("Quantity") - 1
.Edit
.Fields("Quantity") = 1
.Update
End If
End If
End With
rs.MoveNext
Loop
Imagine the following table with the it's data.
Quantity
1.56
2.09
0.99
0.33
4.87
I want the code to do the following precedures:
- Start with the 1stField (1.56). Count the int of 1.56 and replace the result with the field and keep the remain fraction into account and add it to the next field ==> int(1.56) = 1, remained fraction 0.56. The same job for the next fields with looping. Therefore, the code does like this:
Quantity
1 '(0.56) into account to be added to next field => 0.56+2.09=2.65
2 '(0.65) into account to be added to next field => 0.65+0.99=1.64
1 '(0.64) into account to be added to next field => 0.64+0.33=0.97
0 '(0.97) into account to be added to next field => 0.97+4.87=5.84
5 '(0.84) into account to be added to next field => etc.
The source code to be modified is below:
Dim iTotal As Double
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDB
Set rs = db.OpenRecordset("table name",dbOpenDynaset)
rs.Movelast: rs.Movefirst
iTotal = 0
Do Until rs.EOF
With rs
If .Fields("Quantity") < 1 Then
If iTotal + .Fields("Quantity") < 1 Then
iTotal = iTotal + .Fields("Quantity")
.Edit
.Fields("Quantity") = 0
.Update
Else
iTotal = iTotal + .Fields("Quantity") - 1
.Edit
.Fields("Quantity") = 1
.Update
End If
End If
End With
rs.MoveNext
Loop