Can I populate a table's record from a calculation based on entries on a form?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bigdaddrock
    New Member
    • May 2010
    • 67

    Can I populate a table's record from a calculation based on entries on a form?

    I have two entries on an Invoice form: PRICE and QUANTITY (as well as the INVOICE NUMBER).
    In creating a new INVOICE I am pulling in a product's PRICE from a table (though the price may change down the road). On the same form I am entering the QUANTITY of the item being bought. I would like to store the resultant COST (PRICE X QUANTITY) in a table containing the INVOICE NUMBER, QUANTITY, PRODUCT, and COST.
    Any suggestions as to how I might enable the data entry person to just enter the PRICE and QUANTITY on the form, yet record both QUANTITY and COST along with the Invoice Number in an INVOICE TABLE?
    Note, the prices of the products change over time, so the INVOICE's record must reflect the COST of the product at the time it was issued (and not change later just because the price changes).
  • Jerry Maiapu
    Contributor
    • Feb 2010
    • 259

    #2
    Originally posted by Bigdaddrock
    I have two entries on an Invoice form: PRICE and QUANTITY (as well as the INVOICE NUMBER).
    In creating a new INVOICE I am pulling in a product's PRICE from a table (though the price may change down the road). On the same form I am entering the QUANTITY of the item being bought. I would like to store the resultant COST (PRICE X QUANTITY) in a table containing the INVOICE NUMBER, QUANTITY, PRODUCT, and COST.
    Any suggestions as to how I might enable the data entry person to just enter the PRICE and QUANTITY on the form, yet record both QUANTITY and COST along with the Invoice Number in an INVOICE TABLE?
    Note, the prices of the products change over time, so the INVOICE's record must reflect the COST of the product at the time it was issued (and not change later just because the price changes).
    Ok database rule does not allow storing of calculated results in the table though it is possible.
    You can create a query to do calculations.
    Then a form or report can be created based on these queries.

    Ok if you just want view the result (cost) on the form then just create an unbound textbox and on the record source put;
    Code:
    =[name of Quantity text box]*[name of Price text box]
    However, for convenience use a query to do so: Create a query based on your table and select the necessary fields including Price and Quantity and use this format in a new column of the query:
    Code:
    COST: [Price]*[Quantity]
    Set you form's record source to the query and create a text box and set its record source to COST.

    Hope this helps..

    Comment

    • Bigdaddrock
      New Member
      • May 2010
      • 67

      #3
      Query does not resolve issue

      A query would be dynamic in that it would compute the cost at whatever the price happens to be at the time it is run. Since the prices change over time, the computed cost would differ from the originally posted cost.
      Unless you are suggesting that there is a way to utilize a query to post the result to a table, your suggested response will not suffice.

      Comment

      • Jerry Maiapu
        Contributor
        • Feb 2010
        • 259

        #4
        Well ,then you can make use of recordset in VBA by calculating and inserting direct into the desired table from the form.

        Comment

        • Bigdaddrock
          New Member
          • May 2010
          • 67

          #5
          Originally posted by Jerry Maiapu
          Well ,then you can make use of recordset in VBA by calculating and inserting direct into the desired table from the form.
          I am a bit of a novice when it comes to VBA. But I will give it a try. Any suggestions on how I would phrase it in the Recordset??
          Thanks

          Comment

          • Jerry Maiapu
            Contributor
            • Feb 2010
            • 259

            #6
            Originally posted by Bigdaddrock
            I am a bit of a novice when it comes to VBA. But I will give it a try. Any suggestions on how I would phrase it in the Recordset??
            Thanks
            I posted a solution to a similar question half an hour ago here: Solutuion; See Post#9

            If you have any questions with respect to my solution do post it.

            Hope this helps

            Jerry

            Comment

            Working...