Results 1 to 11 of 11
  1. #1
    checkit81 is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2013
    Posts
    5

    Question Txt Box updating two tables

    Hi All Gurus

    i am new here and also new to Access. i am using Access 2003 on XP SP3

    Here is my problem and i hope to get some guidance without much SQL thingy...

    Main form bind to Customer table with ID as PK
    Sub Form bind to Invoice table with ID as FK
    Both tables are related with one to many using ID



    There are some fields in the Sub form for data entry and it is working fine. But i want to add a txt box to this Sub form to enter "Cost". This is fine if i bind this new added txt box to Invoice table with a new field "Cost". What i need is for this "Cost" to be updated into Customer.Cost as well. Filed "Cost" exist in both tables.

    Hope this is clear enough for any guidance less SQL stuff....

    Wish to have some help here as i have been searching the NET for the pass few days.

    Thanks in advance

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Why do you want this in both tables? Sounds like duplication of data and poor db design.
    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.

  3. #3
    checkit81 is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2013
    Posts
    5
    Hi June7

    Thank you for asking . Here is the scenario :
    The Cost changes very often and resides mainly in Customer Table. About 15 product items. The designer of this application is no longer around and i was task to do the mod on the form.

    The request from Management is to change the "Cost" automatically in the Customer Table every time a new "Cost" is used in the invoicing. Else we have to keep track when "Cost" changes.

    Any solutions are welcome or is there a work around ?

    Cheers

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    What is being invoiced? What is 'cost' - the total amount of invoice? I don't understand why cost would be saved with customer and not the invoice record. If cost is the total of multiple items associated with invoice, then this value should not be saved anywhere. Aggregate data should be calculated when needed.
    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
    checkit81 is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2013
    Posts
    5
    Hi June

    "Cost" here refers to "Unit Cost" for each item which is used to compute Quantity*Unit Cost. All aggregate is done using a query. i just need a code or something to be in "after update" or "after insert" in the properties of this data entry txt box.

    Cheers

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    You want to save the unit cost into invoice record so that it will never change for that invoice even if it is changed for the item in the future? If Cost field is included in the form RecordSource, code in some event could be simply:

    Me!Cost = Me.textbox

    Real trick is figuring out what event. Could be the AfterUpdate event of control that selects the product (a combobox?) or BeforeUpdate event of form.
    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.

  7. #7
    checkit81 is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2013
    Posts
    5
    Thanks June. You are right. The text box is bound to Invoice.Cost in the form with the record source = Invoice. The update is to make sure this Unit "Cost" is recorded in Invoice.Cost field of Invoice Table. At the same time, it is to update "Cost" field in Customer.Cost. Reason being Management wanted a consistency across both tables.

    What they want to have is convenience to check Unit Cost to certain Customers in the Customer Table instead of browsing to the Invoice Details. Will your code work, i will play around Before Update or After Update just to see..

    Cheers

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Duplication of data! Horrors! Woe is me! If management has dictated creating this field in Customer table then they don't understand relational database principles. There are ways to provide that view of data without violating basic principles. Users (management) shouldn't even be looking directly at tables.

    I still don't understand this. Isn't there more than one product each with it's own unit cost? What is significance of recording one product's unit cost in Customer table?
    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.

  9. #9
    KathyL is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Aug 2010
    Posts
    94
    What you have, is a “Cost” or “Unit Cost” for each item in invoices.
    And what you have in the Customer table and form, is the most recently recorded Cost. However you update it, it really should not have the same field name, because it is the most recently recorded cost. So call it that, “Last Cost”, or “Most recent Cost”. ( You could have 12 different invoice costs for each month of the year, but you’re storing the last posted one in Customer.)
    June’s correct, you could use either a before update event, or an after update event, to change the Customer field.

  10. #10
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    oooo - scary. This would be a lot smarter to move that Cost into a different table, with FK to the customer table and an effective date on it. That way, you can always see what the Customer's cost should have been at any given date. Otherwise, you can't ever prove that you invoiced him right.

    Ditto on calling the most recent one LastCost or something like that. However, no spaces in table or field names, please.

  11. #11
    checkit81 is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2013
    Posts
    5

    Solved

    Good day everyone...

    i am sorry it took me so long to come here again to reply to all.

    First of all, i want to thank everyone who contributed to this thread and i want to say that this requirement is not needed anymore.

    Thanks to Access Forums and All.

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

Similar Threads

  1. Replies: 5
    Last Post: 12-14-2012, 04:21 PM
  2. Updating Tables
    By Davidyam in forum Access
    Replies: 4
    Last Post: 03-01-2012, 08:36 PM
  3. Updating two tables at once
    By Paul H in forum Forms
    Replies: 2
    Last Post: 10-07-2011, 08:18 AM
  4. VBA not updating the tables
    By weasel7711 in forum Programming
    Replies: 4
    Last Post: 07-16-2011, 03:23 PM
  5. Updating Multiple Tables
    By gazzieh in forum Queries
    Replies: 0
    Last Post: 03-17-2010, 05:59 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