Not able to save data from a field in a form to a table.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Maris99
    New Member
    • Apr 2010
    • 3

    #1

    Not able to save data from a field in a form to a table.

    I have a form with 2 fields. I use the first field to enter a number and if I enter this number, it saves me the number into the related field in the table. This works good. But in the second field I created a formula for this field, to count the number. It is using the number from the first field and multiplies it with another number. It works well because I can see the right number, but it is not saving that calculated number to the related field in the table.
  • Jim Doherty
    Recognized Expert Contributor
    • Aug 2007
    • 897

    #2
    Originally posted by Maris99
    Hi Guys.

    I got a problem.
    I have a form with 2 fields. I use the first field to enter a number and if I enter this number, it saves me the number into the related field in the table. This works good. But in the second field I created a formula for this field, to count the number. It is using the number from the first field and multiplies it with another number. It works well because I can see the right number, but it is not saving that calculated number to the related field in the table.

    Can you help me with that please.

    Thanks
    Welcome to Bytes :)

    Is there any particular need to table store a calculated value?

    I am not saying do NOT do it but generally you should not need to. My guess is that you do not know that a form can be based on a query.

    Look at Access Help - 'Ways to perform calculation in a query' it is all documented

    you will then understand that query can contain a 'formula' as an expression the advantages to you being that it becomes a usuable column in your dataset underlying the form. You only need bind the controlsource of the textbox to the column.

    To help you I have attached a simple db take a look
    Attached Files

    Comment

    • missinglinq
      Recognized Expert Specialist
      • Nov 2006
      • 3533

      #3
      My guess is that you have the formula in the Control Source of the wayward control, While this will display the calculation in the control, a control can only have one Control Source, hence it cannot be bound to the field in the underlying table.

      To do this as you're asking you need to
      1. Change the Control Source of the 2nd control to the field in the underlying table
      2. Place your calculation in the AfterUpdate event of the first control, assigning it to the 2nd control (Me.SecondContro lName = [Your calculation goes here])

      Having said that, it is very seldom that calculations should be stored in tables! Instead, the calculation should simply be recalculated anytime you need it, whether in a form or a report.

      Welcome to Bytes!

      Linq ;0)>

      Addendum: Jim's approach is also valid! In point of fact, I always base forms on queries, even if only one table is involved, for just the reason he gave.

      Comment

      • Maris99
        New Member
        • Apr 2010
        • 3

        #4
        Thanks guys both of the answers helped me a lot. Thanks again

        Comment

        • missinglinq
          Recognized Expert Specialist
          • Nov 2006
          • 3533

          #5
          Glad we could help!

          Linq ;0)>

          Comment

          • Maris99
            New Member
            • Apr 2010
            • 3

            #6
            Alright so I am back once again:) Maybe its just me that I am dumb and not really skilled with access, but I tried to do it the way that I should set the after update field with the expression you wrote me(ofcourse I changed the names:)), but it keeps writing me out this: Microsoft office access can't find the macro `Me.`

            Can you please explain it once again to me how should I change the first field to update the second one with the calculations.

            Thanks a lot guys

            Comment

            • missinglinq
              Recognized Expert Specialist
              • Nov 2006
              • 3533

              #7
              You need to copy and then paste your exact code into a post so we can look at it.

              Linq ;0)>

              Comment

              Working...