Gents,
I do not whant negative value in my calculation for instance
5-12= -7 what kind of VBA code can i use for not allowing negative value note that i want to use for inventory control
Printable View
Gents,
I do not whant negative value in my calculation for instance
5-12= -7 what kind of VBA code can i use for not allowing negative value note that i want to use for inventory control
Look up Help for the ABS function.
Do you just do not want negatives, or do you want it so you can't subtract more than is available?
So, using the Abs function as Allan has said, would yield 7 instead of -7 but if you want only to subtract what is available (so in this case you would only want to subtract 5 instead of 12 because 5 is all that is left) that would require some other calculation. So, which would it be?
You could do something like this:
IIf([Field1]<=[Field2],[Field2]-[Field1],0)
Bob gave you a generic example, now for your original question
Please provide more details where you are using this calculation, is it on a form or in a report? The more details provided in your question, the easier it is for a specific response.Quote:
I do not want negative value in my calculation for instance
5-12= -7 what kind of VBA code can i use for not allowing negative value note that i want to use for inventory control
In the Before Update event (on the form) you can use
Code:If Me.Field1< Me.Field2 Then
Cancel = True
If MsgBox("You can't enter a number greater than available stock. Would you like to try again?", vbQuestion + vbYesNo, "Error") = vbNo Then
Me.Undo
End If
End If