[COLOR=#CC0000]*open up account table
use account in 0
* define variables
Local nbal[/color]
*sql opens tables itself, so no need to open transact.dbf
* changed your iif to result debit and credit as the same field type as amount
* also your balance field needs to be more than N(1)!!!!!!
* if cast doesn't work (if your vfp version is older) use 000000.000 as balance instead, or amount-amount as balance, for the same reason to get the correct type
select tr_date,entry_ref,desc,source_cd,ref1,ref2,acct_no, ;
iif(amount>0, amount, amount-amount) as debit, ;
iif(amount<0, -amount, amount-amount) as credit, ;
Cast(0 as y) as balance ;
from transact order by acct_no,tr_date
COPY TO "c:\documents and settings\administrator\desktop\gl.dbf"
Index on acct_no tag acct_no && accelerate inner scan loop
select account
* gotop not needed, scan always starts from top
scan
[COLOR=#CC0000]nBal = account.ytd_bal[/color] && you missed copying that line, you NEED the initial balance!
select GL
* gotop
scan [COLOR=#CC0000]for[/color] gl.acct_no=account.acct_no [COLOR=#CC0000]&& I said FOR, not WHILE, big difference![/color]
nbal = nbal + gl.debit - gl.credit
[COLOR=#CC0000]* wrong: gl.balance = nbal[/color]
REPLACE balance with m.nbal in gl [COLOR=#CC0000]&& what is so hard in copying code? You can't assign something to a field, you need replace or update-sql[/color]
endscan
endscan
* Select GL not needed, it's still selected from the scan loop
COPY TO "c:\documents and settings\administrator\desktop\GL_20150515.xls" TYPE XL5