Union Query & balance brought forward (1 Viewer)

fibayne

Registered User.
Local time
Today, 02:55
Joined
Feb 6, 2005
Messages
236
Hi...I have been using and modified slightly a sample accounting DB posted by Khawar which has been a great help, I have changed an SQL union query which brought together a client statement with a balance brought forward depending on date criteria selected ...this however is now not working correctly :confused: if anyone is interested in having a look at the db and possibly helping me sort out the error I would be really grateful...I will post the SQl below but think that without the DB it wont be very clear to say the least !

What the report shul dbe doing is looking at the statrt date of the date criteria selected and reporting those transaction after that date with an opening line 'Balance brought forward' with a sum of all previous debits and credits...

it is now showing the opening line for each transaction before the start date rather than a single opening line ???

many thanks for any help
cheers Fi

SELECT VouchersMain.VNum, VouchersMain.VDate, tblAccTranType.Account,tblAccTranType.CurrentAcct,VoucherDetail.txtNarration, IIf([CurrentAcct]="Debit",[TransactionAmount],0) AS Debit, IIf([CurrentAcct]="Credit",[TransactionAmount],0) AS Credit, [Credit]-[Debit] AS Balance, tblApplication.ClientAppID, tblApplication.TitleFALU, tblApplication.ForenameFALU, tblApplication.SurnameLU,tblApplication.policytypeLU,tblApplication.Add1RFA,tblApplication.Add2RFA,tblApplication.Add3RFA,tblApplication.Add4RFA,tblApplication.Add5RFA,tblApplication.PostCodeRFA,tblApplication.CountryRFALU,VouchersMain.ClientID
FROM ((tblClientMain INNER JOIN tblApplication ON tblClientMain.ClientMainID = tblApplication.ClientIDFK) INNER JOIN VouchersMain ON tblClientMain.ClientMainID = VouchersMain.ClientID) INNER JOIN (tblAccTranType INNER JOIN VoucherDetail ON tblAccTranType.AccId = VoucherDetail.AccountId) ON VouchersMain.VNum = VoucherDetail.VNum
WHERE (((VouchersMain.VDate) Between [forms]![frmAccountLedger]![FDate] And [Forms]![FrmAccountLedger]![TDate]) AND ((VouchersMain.ClientID)=[forms]![frmClientPolicyLookUp]![ClientMainID]))
UNION SELECT "" AS VNum, [forms]![frmAccountLedger]![fdATE] AS VD, tblAccTranType.Account, tblAccTranType.CurrentAcct,"Opening Balance Brought forward" AS txtNarration, Sum(IIf([CurrentAcct]="Debit",[TransactionAmount],0)) AS SumOfDebit, Sum(IIf([CurrentAcct]="Credit",[TransactionAmount],0)) AS SumOfCredit, Sum([Credit]-[Debit]) AS Balance, tblApplication.ClientAppID, tblApplication.TitleFALU, tblApplication.ForenameFALU, tblApplication.SurnameLU,tblApplication.policytypeLU,tblApplication.Add1RFA,tblApplication.Add2RFA,tblApplication.Add3RFA,tblApplication.Add4RFA,tblApplication.Add5RFA,tblApplication.PostCodeRFA,tblApplication.CountryRFALU,VouchersMain.ClientID
FROM ((tblClientMain INNER JOIN tblApplication ON tblClientMain.ClientMainID = tblApplication.ClientIDFK) INNER JOIN VouchersMain ON tblClientMain.ClientMainID = VouchersMain.ClientID) INNER JOIN (tblAccTranType INNER JOIN VoucherDetail ON tblAccTranType.AccId = VoucherDetail.AccountId) ON VouchersMain.VNum = VoucherDetail.VNum
WHERE (((VouchersMain.VDate)<[forms]![frmAccountLedger]![FDate]))
GROUP BY"","",tblAccTranType.Account,tblApplication.TitleFALU,tblApplication.ForenameFALU,tblApplication.SurnameLU,tblApplication.policytypeLU,tblApplication.Add1RFA,tblApplication.Add2RFA,tblApplication.Add3RFA,tblApplication.Add4RFA,tblApplication.Add5RFA,tblApplication.PostCodeRFA,tblApplication.CountryRFALU,VouchersMain.ClientID,
tblApplication.ClientAppID,"Opening Balance Brought forward",tblAccTranType.CurrentAcct
ORDER BY VDate, VNum;
 

khawar

AWF VIP
Local time
Today, 04:55
Joined
Oct 28, 2006
Messages
870
can you upload db with some dummy sample data
 

fibayne

Registered User.
Local time
Today, 02:55
Joined
Feb 6, 2005
Messages
236
Hi Khawar...will do thanks having bit of diffs getting it smaller than 1400kb even when zipped though ...will get it sent asap..thanks again cheers Fi
 

fibayne

Registered User.
Local time
Today, 02:55
Joined
Feb 6, 2005
Messages
236
Hi khawar..here it is if you start at 'frmClientPolicyLookUp' select client Smith click on 'statements' ths is the report that isnt working and which is based on your accounting DB sample...thansk for your help and if i can give you any more info please let me know .........cheers Fi
 

Attachments

  • SampleDB.zip
    648.5 KB · Views: 313

khawar

AWF VIP
Local time
Today, 04:55
Joined
Oct 28, 2006
Messages
870
I have created another query query17 based on your query16

and based the report on that query now it shows one line for opening balance

Download the attached file
 

Attachments

  • Copy of 1506_20.04.09_WORKING COPYACCOUNTS_STM Life.zip
    300.1 KB · Views: 438

fibayne

Registered User.
Local time
Today, 02:55
Joined
Feb 6, 2005
Messages
236
Khawar..that's brilliant cant thank you enough...cheers Fi
 

Users who are viewing this thread

Top Bottom