Results 1 to 5 of 5
  1. #1
    joshynaresh is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Aug 2013
    Posts
    131

    Question Update column of one table reference to two column of another table in access 2007

    Suppose I have two table.


    1. LimitTable
    AccNo Name OutstandingBal
    071 Naresh
    072 Ranjan


    2. TxnTable
    AccNo Debit Credit
    071 5000 3000
    072 3000 2000
    071 10000 8000
    072 5000 3000


    I Want to Update LimitTable as
    3. LimitTable
    AccNo Name OutstandingBal
    071 Naresh 4000
    072 Ranjan 3000

    Note: (Debit-Credit) of same account

    Is it possible in access 2007?
    Please help in detail with query/code to me how can I do. Thanking You in advance.

  2. #2
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    Why update the table? Just create a select query. The information is always there.
    Code:
    SELECT LimitTable.AccNo, LimitTable.Name, Sum([Debit]-[Credit]) AS OutstandingBal
    FROM LimitTable INNER JOIN [Txn Table] ON LimitTable.AccNo = [Txn Table].AccNo
    GROUP BY LimitTable.AccNo, LimitTable.Name;
    Calculations should not be stored in tables in a RDBMS. Calculations are performed in queries and run as necessary.

  3. #3
    joshynaresh is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Aug 2013
    Posts
    131
    it works in above table. but when i changed data in [Txn Table] as
    ID AccNo Debit Credit
    7 071 5,000.00
    8 072 3,000.00
    9 071 10,000.00
    10 072 5,000.00
    13 071
    3,000.00
    14 071
    8,000.00
    15 072
    2,000.00
    16 072
    3,000.00
    it returns null value. and I also watn to store in [LimitTable].Outstanding_Bal. Plz Plz help me. Thank You

  4. #4
    joshynaresh is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Aug 2013
    Posts
    131
    i have made mistake. i inserted blank field. when i filled 0 in blank field it woks. but i want to store too.
    I have another question releted with this table about form.Click image for larger version. 

Name:	FORM.jpg 
Views:	8 
Size:	38.8 KB 
ID:	13672 is it Possible. Thank You.

  5. #5
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    and I also watn to store in [LimitTable].Outstanding_Bal.

    This is not a proper way to run a relational database. It is a spreadsheet mindset. When you store calculations in tables, you de-normalize the data. Every time a field changes value, you have to go back and update each of the calculations. As I said earlier, this is something that needs to be done in a query.

    As to the query, you need to wrap the expression in NZ functions.

    Code:
    SELECT LimitTable.AccNo, LimitTable.Name, Sum(NZ([Debit],0)-NZ([Credit],0)) AS OutstandingBal
    FROM LimitTable INNER JOIN [Txn Table] ON LimitTable.AccNo = [Txn Table].AccNo
    GROUP BY LimitTable.AccNo, LimitTable.Name;
    Look at this link on the NZ function http://www.techonthenet.com/access/f...dvanced/nz.php

    Look at this link on why calculations should not be stored. http://allenbrowne.com/casu-14.html and here http://www.utteraccess.com/wiki/inde...d_Audit_Trails

    Here is how you would create a calculation in a form in an unbound control

    http://office.microsoft.com/en-us/ac...010108354.aspx


    This might be a good read also

    htp://forums.aspfree.com/microsoft-access-help-18/access-vs-excel-349267.html

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

Similar Threads

  1. Replies: 3
    Last Post: 09-26-2012, 01:39 PM
  2. Replies: 11
    Last Post: 08-10-2012, 10:25 PM
  3. Replies: 6
    Last Post: 01-13-2012, 09:17 AM
  4. Replies: 1
    Last Post: 12-16-2011, 08:16 AM
  5. Replies: 1
    Last Post: 03-14-2011, 10:04 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