Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating Datasheet Subform from Main Form

Status
Not open for further replies.

torb123

IS-IT--Management
Jan 20, 2005
22
US
I have an orders form with a subform that shows the individual products for the specific order. I am trying to make a button that you can click on to update or change the pricing from what it is currently to the new price (in case it needs updated so I don't need to go throug each one). I have put together some code from things I have read here. It seems to work, but it changes (or updates) the pricing for every order and not just the order I am on. If someone can let me know where I am going wrong, or if I am aproaching it in the wrong way, how to do it?
Code:
Dim rstO As DAO.Recordset
Dim rstT As DAO.Recordset
      Set rstT = Me.Order_Details_Subform.Form.RecordsetClone
      Set rstO = CurrentDb.OpenRecordset("Order Details")

      If rstT.RecordCount > 0 Then
    rstO.MoveFirst
    Do Until rstO.EOF
            rstO.Edit
            rstO!PriceLevel = "MSRP"
            rstO!UnitPrice = Nz(DLookup("MSRP", "Products", "ProductID = " & rstO!ProductID), 0)
            rstO.Update

     rstO.MoveNext
Loop
End If
rstT.Close
rstO.Close
      Set rstT = Nothing
      Set rstO = Nothing
      Me.Order_Details_Subform.Requery

Thanks
 
Thanks jaydeebetoo, but the form requery's fine. It is just that my code changes the price for every order in the database, and I only want it to change prices for the order that is being viewed.
 
Yes, you've open the table "order details", and loop through all of it doing updates on all rows.

What if you try to loop and update the form recordset (rstT)?

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top