Results 1 to 11 of 11

Thread: storing values

  1. #1
    Join Date
    Apr 2004
    Posts
    9

    Post Unanswered: storing values

    Hi


    How can I store the result of an addition between two values in a form to a table .

    For example if you type a value in a field (within a form) it is saved automaticaly, but how can I store a result after doing some calculations with a couple of numbers, or lets say I need to increase the value of a specific field and store that result back in the database.

    Please help
    Dimitris

  2. #2
    Join Date
    Apr 2004
    Location
    Sydney Australia
    Posts
    369
    Just make a macro you click on with a SetValue action where the

    Item is [Forms]![MyForm]![The name of the field where the value goes]

    Expression is [Forms]![MyForm]![textbox name with your calculation]

  3. #3
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Hi Dimitris

    Unless I am missing something, your value should be stored however it comes about (by typing, calculation or any other means). Make sure the text box has the field you want to store the value in as it's control source.

  4. #4
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Ok, I did miss something. Thought the problem was saving rather than calculating

  5. #5
    Join Date
    Apr 2004
    Posts
    9

    re

    here is the problem again

    Iam calculating the total price of an item like '=[field1] + [field2]'
    how can I store the result back in my database in a fild called [res] for example. The macro idea sounds good but how can I triger it every time?

    thanks
    Dimitris

  6. #6
    Join Date
    Apr 2004
    Posts
    9
    Quote Originally Posted by Mike375
    Just make a macro you click on with a SetValue action where the

    Item is [Forms]![MyForm]![The name of the field where the value goes]

    Expression is [Forms]![MyForm]![textbox name with your calculation]

    can not find the set value field
    hlp!!!!

  7. #7
    Join Date
    Apr 2004
    Location
    Sydney Australia
    Posts
    369
    I use Access 95. Perhaps later versions of Access do not call it SetValue but I would doubt that very much.

    Or if go to the OnClick part of Event for the textbox that does the calculation and put

    Private Sub CalcResultTextbox_Click()

    Forms!CommissionPage!FieldMyForm = Forms!CommissionPage!CalcResultTextbox

    End Sub

    The writing in bold type is what will appear when you select Code Builder after clicking ...


    The if you click in the textbox that does the calculation it set the value of the field you choose to be the same value.
    Last edited by Mike375; 05-08-04 at 11:26.

  8. #8
    Join Date
    Apr 2004
    Location
    South Arica
    Posts
    125
    if the field is in the same table as the rest of the data from the current form, then set the controlsource of res to:
    =[field1] + [field2]

  9. #9
    Join Date
    Dec 2003
    Location
    Dallas, TX
    Posts
    1,004
    Quote Originally Posted by mwiec
    Hi

    How can I store the result of an addition between two values in a form to a table .

    Please help
    Dimitris
    Hi mwiec,

    Let me just say for the sake of logical database structuring, that you really should not store a calculated value in a table. That is one of the rules that keeps headaches away in the future, though few do break it and able to cope. Now that I've said that, you should create the calculations in your Query/Form, then create a TextField to store the result for later use. IF, for some reason you just have to store the value in your Table, then create an UpdateQuery to change the results of that field in your table when you wish to have it changed. Do you want that field changed everytime you calculate it? Create the Query then have a CommandButton for that item to UPDATE, and click it when you wish to change that value. I would recommend an UpdateQuery over a macro, reason being, if you transfer that table and forms, you have to remember to take the associated queries that apply to those fields also. If you do this in SQL queries or calculated fields in the forms, all the calculations go with the forms, no need to remember where they are.
    Now, to explain why I say what I do in a logical manner, and a lesson I learned the hard way. I had a table for my inventory program I inherited and maintain and not really thinking into it logically, I changed the prices on some of the items, as the Vendors went up or down on what they were charging us. BAD NIGHTMARE This is what you are being cautioned about. I didn't think what I did caused any problems. WELL, when I changed that unit price, ALL of the HistoricalData for the records in the past.....also were changed. This came to light when they did the books and inventory. They had no way of knowing what things had cost back on those past dates. When I changed it for one, I changed it for all....past and future. That means the dollar values were like WAY OFF. THAT is the point I was trying to bring to light. Since then I have learned from some very intelligent database programmers. So I try to Pay It Forward. Knowledge is no good if you keep it to yourself.
    Just trying to help out. Hope this helps you as it was my sincere intention to do just that. The choice is upon you
    Have a great weekend.
    Bud

  10. #10
    Join Date
    Apr 2004
    Posts
    9

    again

    Thank all for your infos

    this is what i need to do (I should have said that from the start).

    I have a subform that keeps a cost for parts and i need to calculate the total price (price times number of items + tax) for each row and then calculate the total after adding all up (using '=Sum(total_price') but I find that this gives me an error or adds up only the values that are stored in the table rather than values calculated with rice times number of items + tax.
    So when I create a field called tot_pr and make it equal to
    (x1+x2)*0.tax the expresion at the bottom of the form '=sum(tot_pr)' gives an error

    Another question whats the corresponding expression
    of
    forms![form_name]![field_name]
    but for tables (to address a field within a table and change it to something)

    ???????![table_name]![field_name] fill in the q-marks?????)

    Not my best weekend in my life
    Thank you all

  11. #11
    Join Date
    Dec 2003
    Location
    Dallas, TX
    Posts
    1,004
    mwiec

    Hello again mwiec, take a look at this and see if it's kinda like what you're talking about...I'll be checking back later.

    Bud
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •