how can i update a field in a table from a form ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • hannoudw
    New Member
    • Aug 2010
    • 115

    #1

    how can i update a field in a table from a form ?

    Hi i have this table:
    item (article# , price , PRICE_AFTER_DIS COUNT)
    i wanna update PRICE_AFTER_DIS COUNT how can i do it? if it's at the first place = null
  • jimatqsi
    Moderator Top Contributor
    • Oct 2006
    • 1293

    #2
    Well, you don't give us a lot to go on, but let's make some assumptions. I assume the article number (let's not use the pound sign as part of an identifier) is all you need to identify the item in the table. Also assume you want the price after discount updated after changing the price value.

    I assume also that the 3 data items all appear on the form. Let's say they are in text boxes and the text box names are txtArticle, txtPrice, txtPriceAfterDi scount.

    One further assumption we'll make is that the discount is 10% of the regular price.

    Here's how you make your update. In the AfterUpdate event of the txtPrice ojbect, put this code.
    Code:
    me!txtPriceAfterDiscount=round(me!txtPrice - (me!txtPrice*.10),2)
    Oh dear, I see I made another assumption, that being you want 2 decimal precision, and we don't even need the assumption about the article number being the primary key. Anyway, I think you have enough to start with.

    Let us know how far this takes you.

    Jim

    Comment

    • hannoudw
      New Member
      • Aug 2010
      • 115

      #3
      thanks Jim
      i have another question
      i'm now doing the invoice customer form
      and i had those text box :
      txtarticle, txtPrice, txtAfterDiscPri ce, txtCashMoney
      i want to write this code
      Code:
      If (txtAfterDiscPrice is null) then txtCashMoney=txtPrice ;
      else 
      txtCashMoney=txtAfterDiscPrice;
      on the default value of the txtCashMoney.

      so i wrote this on the default value of the txtCashMoney:
      Code:
      = iif(isnull(txtAfterDiscPrice ) ,= [txtPrice] ,= [txtAfterDiscPrice ]
      but it's not working does anyone know why ?

      Comment

      • jimatqsi
        Moderator Top Contributor
        • Oct 2006
        • 1293

        #4
        Is txtCashMoney bound to a data item? I'm not sure the object default value is the place to put that. Maybe you could put that code in the OnCurrent event of the form; then it would get executed for the current detail line whenever you change from one row to another.

        But I'm not sure you want to do that either. A lot depends on the business rules and processes surrounding this form. Is the form the source for getting pricing into the inventory database? If yes, then the AfterUpdate event of the txtPrice object is the perfect place to update the discounted price. The discounted prices get updated one at a time just as you enter/edit the price.

        However, if the prices are being imported from elsewhere, maybe it would be better to have a query that updates all the discounted prices at once, based on the price already stored in each item.

        Jim

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32669

          #5
          Forget that Jim. This question has subsequently been asked and answered elsewhere (iif statement in a default value not working).

          Hannoudw,

          Please do not post multiple questions in the same thread. It is against the rules because it causes confusion and wastes a lot of the time of those members who are making efforts to help you.

          It might show good manners if you checked out the rules before continuing to use the services.

          Comment

          • hannoudw
            New Member
            • Aug 2010
            • 115

            #6
            @NeoPa
            sorry about that i didn't knew it :(

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32669

              #7
              And now you do but have posted twice more since then.

              These have been deleted. You will get notification of that so you can repost them properly if you need to.

              I am now locking this thread.

              Comment

              Working...