Hi,
I am very new to Access and wondered if anyone could help with a syntax error I have with my VBA.
I have a table, and 3 fields which should update a 4th field, but referencing 3 other tables - each linked to one of the 3 fields. This section seems to work fine, however I want it to do it for every record in the table and currently it only does it for the first one.
I have tried using the For Each statement, but this is apparently invalid for "this type of object".
Any ideas of how I can declare things differently?
Thanks
Zoe
My code is as follows:
I am very new to Access and wondered if anyone could help with a syntax error I have with my VBA.
I have a table, and 3 fields which should update a 4th field, but referencing 3 other tables - each linked to one of the 3 fields. This section seems to work fine, however I want it to do it for every record in the table and currently it only does it for the first one.
I have tried using the For Each statement, but this is apparently invalid for "this type of object".
Any ideas of how I can declare things differently?
Thanks
Zoe
My code is as follows:
Code:
Private Sub cmdUpdate_Click()
Dim rcdTesting As DAO.Recordset
Dim rcdReference As DAO.Recordset
Dim rcdReference2 As DAO.Recordset
Dim rcdReference3 As DAO.Recordset
Dim I As Variant
Dim Constant As Integer
Dim Constant2 As Integer
Dim Constant3 As Integer
Set rcdTesting = CurrentDb.OpenRecordset("tblTest2")
Set rcdReference = CurrentDb.OpenRecordset("tblReference")
Set rcdReference2 = CurrentDb.OpenRecordset("tblReference2")
Set rcdReference3 = CurrentDb.OpenRecordset("tblReference3")
With rcdTesting
For Each I In rcdTesting
.Edit
If ![Outing] = rcdReference![Value] Then
Constant = rcdReference![Result]
End If
If ![Lap] = rcdReference2![Value] Then
Constant2 = rcdReference2![Result]
End If
If ![Time] = rcdReference3![Value] Then
Constant3 = rcdReference3![Result]
End If
![Value].Value = Constant * Constant2 * Constant3
.Update
Next
End With
End Sub
Comment