Hi,
I am a complete novice to Access VBA and looking for some help to select a record. I am looking to perform an operation on the previous record - i.e. adding a new blank field, and then calculating the value in the new field by increasing the value in the previous record by a percentage. However, I am unsure of how to select the previous record. I though that by having a query in the background which finds the maximum record ID would work, however, I can't work out how to translate this to a record selection.
My code is as follows:
The rows with ********* alongside are the ones with the syntax errors.
Any help greatly appreciated,
Kind regards,
Zoe
I am a complete novice to Access VBA and looking for some help to select a record. I am looking to perform an operation on the previous record - i.e. adding a new blank field, and then calculating the value in the new field by increasing the value in the previous record by a percentage. However, I am unsure of how to select the previous record. I though that by having a query in the background which finds the maximum record ID would work, however, I can't work out how to translate this to a record selection.
My code is as follows:
Code:
Private Sub cmdUpdate_Click() Dim rcdBudgetShareProj As DAO.Recordset Dim rcdMaxID As DAO.Recordset Dim Percent As Double Dim MaxID As Integer Dim I As Integer Percent = 1 + Nz(Forms!frmTest![Percent], 0) Set rcdBudgetShareProj = CurrentDb.OpenRecordset("tblTest") Set rcdMaxID = CurrentDb.OpenRecordset("qryMaxID") MaxID = (rcdMaxID![MaxID]) - 1 With rcdBudgetShareProj For I = 1 To 3 Call .AddNew ![Year] = intYear + 1 ![Outing] = ![Outing].MaxID * (Percent ^ I) *************** ![Increase] = Percent ![Time] = ![Time].MaxID * (Percent ^ I) **************** Call .Update Next I End With End Sub
Any help greatly appreciated,
Kind regards,
Zoe
Comment