Results 1 to 10 of 10
  1. #1
    rajudh is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Mar 2020
    Posts
    12

    Opening balance not showing on Access Report

    Hello, I have Access 2013, 64 bit version.
    I have made a database with 2 tables, made query for closing balance, Criteria for Date Range and Customer ID search from Form, Form with Search Button, Report that showing with criteria Customer ID and Date range.
    I made a Text box in report for showing Opening balance which is date before from date field in form.
    Say Report date is between 01 May 2025 to 20 May 2025, it should be show Opening balance of sum of Debit - Credit for 30 April 2025. It may be Debit or Credit balance carry forward in Text box.
    I tried Code in Control Source -
    =DLookUp("[Debit] - [Credit]","[Query1]","[Trans_Date]<#" & [Forms]![Frm1]![TxtFromDate] & "#")


    but not working.
    Please help me.New Dr & Cr - Copy.zip

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,927
    ‘Not working’ means nothing- you get an error? Wrong result?

    best guess is either debit or credit is null or your date is not formatted in either the sql standard of yyyy-mm-dd or the us format of mm/dd/yyyy

    or perhaps your criteria is wrong - it will return the first record that matches the criteria

  3. #3
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,421
    In your report calculated control for "Sum Debit" try
    Code:
    =DSum("Debit","CustomerT","[Forms]![Frm1]![CmbCustID] AND Month(Trans_Date) = Month(Date())-1")
    and do the same for Credit textbox then in opening balance textbox, subtract the two values.

    This part Month(Trans_Date) = Month(Date())-1 will look at data in the prior month only. If you want to be able to do something else, you'll have to use a date value from somewhere else. In that case, you likely would not want to subtract 1 from that date.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Your query does not calculate balance. The DLookup attempts to look at only one record. You need to aggregate records. DLookup won't do that. Use DSum. The query doesn't do any aggregating and really isn't needed. Try:

    =DSum("[Debit] - [Credit]","[CustomerT]","[Trans_Date]<#" & [Forms]![Frm1]![TxtFromDate] & "# AND CustID=" & [Forms]![Frm1]![CmbCustID])

    If you want to use a query and DLookup, the query must aggregate records for specified period.

    I don't understand your Debit and Credit fields. Why are withdrawal types a debit and deposits a credit? How can there be withdrawals before any deposits?


    I avoid dynamic parameterized queries. I prefer VBA building filter criteria and applying to form or report.


    Why are Debit and Credit fields set as Long Integer? Really need to be Double or Currency probably best.

    Strongly advise not to use punctuation/special characters (underscore only exception) in naming convention.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    rajudh is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Mar 2020
    Posts
    12
    Thanks CJ_London,
    Not working means it was giving blank value. There is no transaction before 01/05/2025. So I changed my system date to dd-MMMM-yy, this give me date as 24-May-25 and add record on 30 Apr. 25 as Deposit in Credit column, write code suggested by "June7" as -
    =DSum("[Credit]-[Debit]","[CustomerT]","[Trans_Date]<#" & [Forms]![Frm1]![TxtFromDate] & "# AND CustID=" & [Forms]![Frm1]![CmbCustID])"
    It worked perfectly.
    Click image for larger version. 

Name:	Access.jpg 
Views:	19 
Size:	68.2 KB 
ID:	53039
    Another thing is I added a running closing balance field in details section from my "Query1' but error message is appeared as "Multy-level group by clause is not allowed in subquery".
    how to solve it ?
    if I simply add [Credit]+[Debit] in that field it does not take Opening balance into consideration. If I add Opening balance from Report Header it gives wrong calculation. It should give Opening balance + credit - Debit for start date and this should be carry forward as opening balance to next day add credit - debit for that day.

    ex.
    Op. bal. as on 30 Apr. 25 = 5,000.00

    Date Trans_ID Trans. Type Debit Credit Closing Balance
    02-May-25 2 Deposit 0.00 2,000.00 7,0000.00
    03-May-25 3 Withdrawal 1,000.00 0.00 6,0000.00
    04-May-25 4 Withdrawal 1,000.00 0.00 5,0000.00

  6. #6
    rajudh is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Mar 2020
    Posts
    12
    Thanks
    First your code was not working. then I changed my date format to dd-MMMM-yy.
    Your code worked perfectly.
    thanks again.

  7. #7
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,927
    Understand what a date field actually is - which is a decimal number. The value before the decimal point is the number of days since 31/12/1899 and the value after the number of seconds in the date divided be 86400 - the total number of seconds in 24 hours. What you see is just a format of the date.

    so

    ?now() & " >>> " & cdbl(now())
    25/05/2025 12:17:49 >>> 45802.5123726852

    If you were in the US you would have seen

    05/25/2025 12:17:49 >>> 45802.5123726852

    so to use a formatted value (which is a string) in SQL you need two things - the # identifiers which tells SQL that the string between then is to be interpreted as a date. And the string itself should be unambiguous otherwise it will default to the US standard.

    So 25/05/2025 is unambiguous because SQL knows there are not 25 months in the year so automatically swaps the two elements around.

    A date like 12/05/2025 is ambiguous and will be treated as 5th December, not 12th May.

    A string like 12 May 2025 is not ambiguous because the month is clearly specified.

    The sql standard is yyyy-mm-dd and personally my preferred format when using sql

    So I would have suggested

    =DLookUp("[Debit] - [Credit]","[Query1]","[Trans_Date]<#" & format([Forms]![Frm1]![TxtFromDate],"yyyy-mm-dd") & "#")

    No need then to change the format of your textbox

  8. #8
    rajudh is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Mar 2020
    Posts
    12
    Thank you
    I did not know this.

    Another thing is I added a running closing balance field in details section from my "Query1' but error message is appeared as "Multy-level group by clause is not allowed in subquery".
    how to solve it ?
    if I simply add [Credit]+[Debit] in that field it does not take Opening balance into consideration. If I add Opening balance from Report Header it gives wrong calculation. It should give Opening balance + credit - Debit for start date and this should be carry forward as opening balance to next day add credit - debit for that day.

    ex.
    Op. bal. as on 30 Apr. 25 = 5,000.00

    Date Trans_ID Trans. Type Debit Credit Closing Balance
    02-May-25 2 Deposit 0.00 2,000.00 7,0000.00
    03-May-25 3 Withdrawal 1,000.00 0.00 6,0000.00
    04-May-25 4 Withdrawal 1,000.00 0.00 5,0000.00

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Three textbox calculations:

    Op. Balance
    =Nz(DSum("[Debit] - [Credit]","[CustomerT]","[Trans_Date]<#" & [Forms]![Frm1]![TxtFromDate] & "# AND CustID=" & [Forms]![Frm1]![CmbCustID]),0)

    Running Sum Over All or Over Group (can set this one not visible)
    =[Debit]-[Credit]

    Balance - sum the first two
    =Text29 + Text43
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    rajudh is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Mar 2020
    Posts
    12
    Click image for larger version. 

Name:	Access 01.jpg 
Views:	8 
Size:	27.8 KB 
ID:	53044
    Thank you once again,
    It worked as I want.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Opening Balance and Closing Balance
    By SHIVA2016 in forum Queries
    Replies: 2
    Last Post: 04-22-2023, 09:46 AM
  2. Opening balance worked into running balance.
    By Perfac in forum Programming
    Replies: 11
    Last Post: 01-09-2018, 01:20 PM
  3. How To Get Running Balance Of Customer with last balance
    By muhammadirfanghori in forum Access
    Replies: 1
    Last Post: 10-25-2016, 03:31 PM
  4. General Ledger Query With Opening Balance and Running Balance
    By muhammadirfanghori in forum Queries
    Replies: 3
    Last Post: 03-12-2015, 07:17 AM
  5. Replies: 1
    Last Post: 03-29-2014, 10:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums