• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 409
  • Last Modified:

updating all records in subform

I have a little code that copies amounts from one field to another but it is only updating the first record in the subform. How would I get it to update all the records in the given subform?

If Me.AccountTypeID = 1 Then
[sbfrmOrders].Form.UnitPrice = [sbfrmOrders].Form.cUnitPrice
[sbfrmOrders].Form.TotalPrice = [sbfrmOrders].Form.Quantity * ([sbfrmOrders].Form.cUnitPrice)
[sbfrmOrders].Form.SpecialDiscount = 0
Else
[sbfrmOrders].Form.UnitPrice = [sbfrmOrders].Form.cUnitPrice
[sbfrmOrders].Form.TotalPrice = [sbfrmOrders].Form.Quantity * ([sbfrmOrders].Form.cUnitPrice - [sbfrmOrders].Form.cUnitPrice * [sbfrmOrders].Form.SpecialDiscount)
End If

Open in new window

0
Shawn
Asked:
Shawn
1 Solution
 
GrahamMandenoCommented:
Hi Shawn

You can visit every record in a form (or subform) by looping through the RecordsetClone:
Dim rsc as DAO.Recordset
Set rsc = [sbfrmOrders].Form.RecordsetClone
rsc.MoveFirst
Do Until rsc.EOF
    rsc.Edit
    If Me.AccountTypeID = 1 Then rsc!SpecialDiscount = 0
    rsc!UnitPrice = rsc!cUnitPrice
    rsc!TotalPrice = rsc!Quantity * rsc!UnitPrice * (1 - rsc!SpecialDiscount )
    rsc.Update
    rsc.MoveNext
Loop

Open in new window

Best wishes,
Graham Mandeno [Access MVP 1996-2013]
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now