Calculation of two dependent variables in Access Query I'm having problem constructing below two variables in Access Query or Access SQL which are dependent on each other, please kindly help!

a(n)=b(n)+c(n);
b(n)=if(a(n-1)&lt;>0,a(n-1),d(n)).

n refers to the current record while n-1 refers to the previous record.

Here's the sample data:
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;