Solved

updating all records in subform

Posted on 2013-05-31
1
383 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

749 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