I have a form with a subform on it. The sub form uses two of the fields on the main form to provide criteria to the subform's underlying query. The subform returns 12 records, one for each month of the year. The final field in subform's query is a calculated field (calculates a new price). I put a button on the main form and attached some code to let it udate the price table with the newly calculated prices from the subform. The main form is named frmSFPPriceMain, the subform is frmSFPPriceSub, and I want to update the [CalculatedPrice] field from the subform to a field named FinalPrice in a table called tblUPCPrices. Here is the code
Sub UpdateSFPPrices()
On Error GoTo UpdateSFPPrices_err
Dim dbs As Database, rst As Recordset
' Return Database variable pointing to current database
Set dbs = CurrentDb
Set rst = dbs.openRecordset("SELECT * FROM tblUPCPrices WHERE (([ProductID]=[FORMS]![frmSPFPriceMain].[ProductID]) AND ([Year]=[FORMS]![frmSPFPriceMain].[PriceYear]));")
With rst
' Edit the Recordset object
.Edit
'Edit the field
![FinalPrice] = Forms![frmSFPPriceSub].[CalculatedPrice]
.Update 'Save Changes
End With
dbs.Close
UpdateSFPPrices_Exit:
Exit Sub
UpdateSFPPrices_err:
MsgBox Err.Description
Resume UpdateSFPPrices_Exit
End Sub
I get an error when it hits the "Edit" line in the code. The error is "Method or Data Member not Found". I thought I had to use the "Edit" method to modify the Recordset. Finally will this update all the records in the Recordset or just the current record? If just the current Recordset, how do I get it to update all the records?
Sub UpdateSFPPrices()
On Error GoTo UpdateSFPPrices_err
Dim dbs As Database, rst As Recordset
' Return Database variable pointing to current database
Set dbs = CurrentDb
Set rst = dbs.openRecordset("SELECT * FROM tblUPCPrices WHERE (([ProductID]=[FORMS]![frmSPFPriceMain].[ProductID]) AND ([Year]=[FORMS]![frmSPFPriceMain].[PriceYear]));")
With rst
' Edit the Recordset object
.Edit
'Edit the field
![FinalPrice] = Forms![frmSFPPriceSub].[CalculatedPrice]
.Update 'Save Changes
End With
dbs.Close
UpdateSFPPrices_Exit:
Exit Sub
UpdateSFPPrices_err:
MsgBox Err.Description
Resume UpdateSFPPrices_Exit
End Sub
I get an error when it hits the "Edit" line in the code. The error is "Method or Data Member not Found". I thought I had to use the "Edit" method to modify the Recordset. Finally will this update all the records in the Recordset or just the current record? If just the current Recordset, how do I get it to update all the records?