Calculation of two dependent variables in Access Query
I've got an answer from my friend below but it works very slow for my actual database. 

Anyone has more efficient way doing it?

Table1

| ID n  c  d |
|------------|
| 1  1  1  2 |
| 2  2  0  2 |
| 3  3  0  2 |
| 4  4  1  2 |
| 5  5  2  2 |
| 6  6  3  2 |
| 7  7 -9  2 |


n=ID but n is number variable
sql:

SELECT Table1.n
    ,[b] + [c] AS a
    ,IIf([n] &lt; 2, 2, IIf(DLookUp("[a]", "Query2", "[table1].[n]=" &amp; [table1].[n] - 1) &lt;&gt; 0
         , DLookUp("[a]", "Query2", "[table1].[n]=" &amp; [table1].[n] - 1), [d])) AS b
    ,Table1.c
    ,Table1.d
FROM Table1;