Storing Calculated Value (special senerio)

robsworld78

Registered User.
Local time
Yesterday, 23:58
Joined
May 31, 2011
Messages
99
Hi, I know you shouldn't store calculated values but this is a special case I believe.

I'm playing with inventory, we have cases, boxes and pieces. A case could have 4 boxes and each box has 12 pieces.

When I transfer inventory I use cases, so if I need to transfer only half a case I go .5.

Now I've come across a senerio where I may need to take inventory out so I will just enter a negative number -.5 for half a case. Works fine.

Here's the problem. I may only want to take out 6 pieces which is half a box, so I can't enter that in cases very easy, it would be like .0082 or something like that. So what I want to do is have another text box where I enter the number of pieces I want to remove and with math in the cases box it will say that's .0082 cases or whatever but it needs to store that value because that's the field I use for everything.

So how do I do that calculation and store it in the "casestransfered" field?

Right now I have it so I enter the pieces it does the math in an unbound textbox and then I enter what's in the calculated text box in the bound "casestransfered" field but I want it to store automatically from the unbound text box that's doing the math.
 
You can write some code like this:

me.casestransfered = me.myPieceInputBox * caseFactor


In the above example, caseFactor is a variable. The other two elements starting with me. are references to text boxes on your form.

You need to decide how you want to run the code. For instance you could use the AfterUpdate event for the input box. So when the user types a number then presses enter (or tab), the code will fire. Or you could use a button so it is more obvious to the user what they are doing.

hth
Chris
 
Thanks, that was too easy, why can't everything be this easy. :)
 
Oh one other related thing. I'm doing the same trick on another form and the field that is doing calculating I want that number to be stored. It's the payment amount I'm capturing.

Someone enters the payment as 2 - $20, 1 - $10 and the total says $30 paid then I want that number to go into the "PaymentAmount" field which I can do now thanks to you! However I can't get that number over automatically using the events. I had to go with onclick and after the field calculates the value I click it and it moves to the "PaymentAmount" but I want it automatically, just like the calculated field works.

Any ideas?
 
I have a hard time pulling from different subforms, it always seems to be done a different way and I haven't figured out why yet. Anyways this trick works great if everything is on the same subform but for the life of me I can't get it to call info from another subform, please help.

This is the code I use

Me.BarsSold = Me.BarsReturned

Works great, when I put numbers in BarsReturned it moves them to BarsSold. But I want it to be like this.

Me.BarsSold = VendorInventoryLevelSubform.BarsGiven - Me.BarsReturned.

I've tried so many senerios for BarsGiven but it won't call that number. I've gone me.parent.VendorInventoryLevelSubform.barsgiven I've tried in many different brackets sometimes with me.parent. etc...

I've been trying using different senerios with BarsGiven as in brackets and dots, etc...

Me.BarsSold = VendorInventoryLevelSubform.BarsGiven
 

Users who are viewing this thread

Back
Top Bottom