
Originally Posted by
June7
One way is with DLookup.
Value from field of recordset current record could be in the WHERE CONDITION. I am not quite following your code logic, but something like:
DLookup("NodeID", "tablename", "ParentID=" & rs!ParentID)
So...
Code:
Sub Calculations()
'define variables
Dim db As DAO.Database
Dim qryPar As DAO.QueryDef
Dim levels As Long
Dim pl As Double
Dim rsTemp As DAO.Recordset
Dim rsResults As DAO.Recordset
Dim strSQL As String
Dim FindRecordCount As Long
Dim i As Long
Dim fieldPosition As Long
On Error GoTo ErrorHandler
Set db = CurrentDb()
levels = DMax("LEVEL", "T_example")
DoCmd.SetWarnings False
'loop to go through the hierarchy by levels
While levels > 1
'create a temporary table called T_Results
Set qryPar = db.QueryDefs("q1")
qryPar.Parameters("Child level") = levels
qryPar.Execute
'Create a query to sum current level to appropriate parent
strSQL = "SELECT * FROM T_example LEFT JOIN T_Results ON T_example.NODEID = T_Results.PARENTID"
'Calculate the New value going through each Record in the joined query
Set rsResults = db.OpenRecordset(strSQL, dbOpenDynaset)
rsResults.MoveFirst
Do While Not rsResults.EOF
'Processes the calculation
rsResults.Fields.Item("Data_Value").Value = rsResults.Fields.Item("Data_Value").Value + rsResults.Fields.Item("SumOfData_Value").Value
rsResults.MoveNext
Loop
levels = levels - 1
DoCmd.RunSQL "DROP TABLE T_Results"
Wend
DoCmd.SetWarnings True
ErrorHandler:
MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description
End Sub
but the recordset is not updatable...
How can I put it updatable?