Solved

updating all records in subform

Posted on 2013-05-31
1
370 Views
Last Modified: 2013-06-18
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
Comment
Question by:Shawn
1 Comment
 
LVL 20

Accepted Solution

by:
GrahamMandeno earned 500 total points
ID: 39212214
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question