V
vcsphx
Hi all,
I am working on developing an application for my company and I have got
struck up with a step where, it looks like, I need to do a loop through my
records. I have given a sample recordset similar to the one I have below
where I have 5 fields and the fifth field in that, which is called "Total" is
going to be the calculated field and that's where I need a looping. What that
field signifies is Total==(quantity*Percent) if 'Number' field=0; else for
each Order Type: (quantity-number)*percent)…in this case it would be 25. I
have given the coding that I tried below the sample data. But apparently it's
not the way to appoach it. Can any of you suggest why it's not working and
maybe a better way of achieving this? I would really appreciate your help on
this. Thanks!
Order Quantity Percent Number Total
A 100 50% 25
A 100 50% 25
A 100 50 50
B 200 50% 100
B 200 50% 100
Private Sub cmdCalc_Click()
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim Order As Field
Dim quantity As Field
Dim number As Field
Dim total As Field
Dim percent As Field
With rs
..CursorType = adOpenDynamic
..Open "sheet1", CurrentProject.Connection
End With
Do While Not rs.EOF
For Each rs!Order In rs
If rs!number = 0 Then
rs!total = rs!quantity * rs!percent
Else
rs!total = (rs!quantity - rs!number) * rs!percent
End If
Next rs!Order
Loop
End Sub
I am working on developing an application for my company and I have got
struck up with a step where, it looks like, I need to do a loop through my
records. I have given a sample recordset similar to the one I have below
where I have 5 fields and the fifth field in that, which is called "Total" is
going to be the calculated field and that's where I need a looping. What that
field signifies is Total==(quantity*Percent) if 'Number' field=0; else for
each Order Type: (quantity-number)*percent)…in this case it would be 25. I
have given the coding that I tried below the sample data. But apparently it's
not the way to appoach it. Can any of you suggest why it's not working and
maybe a better way of achieving this? I would really appreciate your help on
this. Thanks!
Order Quantity Percent Number Total
A 100 50% 25
A 100 50% 25
A 100 50 50
B 200 50% 100
B 200 50% 100
Private Sub cmdCalc_Click()
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim Order As Field
Dim quantity As Field
Dim number As Field
Dim total As Field
Dim percent As Field
With rs
..CursorType = adOpenDynamic
..Open "sheet1", CurrentProject.Connection
End With
Do While Not rs.EOF
For Each rs!Order In rs
If rs!number = 0 Then
rs!total = rs!quantity * rs!percent
Else
rs!total = (rs!quantity - rs!number) * rs!percent
End If
Next rs!Order
Loop
End Sub