By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,940 Members | 1,300 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,940 IT Pros & Developers. It's quick & easy.

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

P: 115
Hi i have this table:
item (article# , price , PRICE_AFTER_DISCOUNT)
i wanna update PRICE_AFTER_DISCOUNT how can i do it? if it's at the first place = null
Aug 5 '10 #1
Share this Question
Share on Google+
6 Replies

Expert 100+
P: 1,240
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, txtPriceAfterDiscount.

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.
Expand|Select|Wrap|Line Numbers
  1. 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.

Aug 5 '10 #2

P: 115
thanks Jim
i have another question
i'm now doing the invoice customer form
and i had those text box :
txtarticle, txtPrice, txtAfterDiscPrice, txtCashMoney
i want to write this code
Expand|Select|Wrap|Line Numbers
  1. If (txtAfterDiscPrice is null) then txtCashMoney=txtPrice ;
  2. else 
  3. txtCashMoney=txtAfterDiscPrice;
on the default value of the txtCashMoney.

so i wrote this on the default value of the txtCashMoney:
Expand|Select|Wrap|Line Numbers
  1. = iif(isnull(txtAfterDiscPrice ) ,= [txtPrice] ,= [txtAfterDiscPrice ] 
but it's not working does anyone know why ?
Aug 5 '10 #3

Expert 100+
P: 1,240
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.

Aug 6 '10 #4

Expert Mod 15k+
P: 31,769
Forget that Jim. This question has subsequently been asked and answered elsewhere (iif statement in a default value not working).


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.
Aug 6 '10 #5

P: 115
sorry about that i didn't knew it :(
Aug 6 '10 #6

Expert Mod 15k+
P: 31,769
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.
Aug 6 '10 #7

This discussion thread is closed

Replies have been disabled for this discussion.