Solved

updating all records in subform

Posted on 2013-05-31
1
389 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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 …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

738 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