Results 1 to 3 of 3
  1. #1
    mitchel is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Feb 2012
    Posts
    9

    Substracting values from textbox to insert in Table.

    Hi, I've been working on a small project and I got a problem. What I'd like is to substract a value from a text box with the value from another textbox and insert the result in the database.
    E.G.
    txtBox Quantity: 10
    txtBox Quantity used: 4
    It'd then update Quantity with "Quantity-Quantity used" and reset the Quantity used to 0. I know how to do substraction but I haven't figured out how to used the txtBox that does the substraction to insert into the Table.

    Another way I thought of is filling both text box and doing the calculation when you update the selected row.



    I'm currently using a macro that does something similar but it's very ineffective because it updates every field in my database which slows the whole thing.

    Hope this is clear enough.

    Thanks

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,953
    Why do you need to save calculated value? A principle of database design is 'enter raw data, do calcs in reports'. This is especially true with aggregate calcs.

    However, if you must.

    If the Quantity field is part of the form's RecordSource, can simply set the field's value in some event (form Close, button Click, textbox AfterUpdate). I don't use macros, only VBA. In the event property, select [Event Procedure], double click the ellipses (...). This will take you to the procedure in VBA editor. Type code:
    Me!Quantity = Me.tbxQuantity
    Me.tbxUsed = 0
    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
    mitchel is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Feb 2012
    Posts
    9
    While I understand it'd be better to do it during a report, I still needed to do it in the form. Your code worked.

    Thank you.

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

Similar Threads

  1. Multiple Values in textbox
    By frksdf in forum Forms
    Replies: 10
    Last Post: 07-14-2014, 11:41 AM
  2. Insert Multiple Checkbox Values to one Textbox
    By dshillington in forum Programming
    Replies: 1
    Last Post: 12-28-2011, 10:10 AM
  3. Substracting months to a date
    By ruthib4 in forum Queries
    Replies: 2
    Last Post: 12-21-2011, 10:11 AM
  4. Replies: 1
    Last Post: 11-18-2011, 08:12 AM
  5. Replies: 0
    Last Post: 03-08-2011, 05:56 PM

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