Calculate Margin on every change

LeeHutchins

New member
Local time
Today, 14:41
Joined
Nov 3, 2020
Messages
13
Hi,

I want my margin to calculate with every change of PAPrice usually would use me.FIELDNAME.text but this is a numeric value and doesn't seem to work that way.

this is what I have so far, but might be wayyyyyyy off.

Code:
Private Sub PAPrice_Change()
   If Len(Me.PAPrice) > 0 Then
         Me.Margin = (Me.PAPrice - Me.StandardCost) / Me.StandardCost
         Me.Margin.Enabled = False
   End If
End Sub

with thanks,

Lee
 
Hi. I don't understand your comment about using the Change event on a numeric field. I just tried it, and it was working fine. What was happening when you tried it?
 
Hi. I don't understand your comment about using the Change event on a numeric field. I just tried it, and it was working fine. What was happening when you tried it?
The margin field is still blank with no change?

What I mean is that on every new number entered eg for 1.75 it updates on the '1', then the '1.' then the '1.7', then the '1.75',
 
The margin field is still blank with no change?

What I mean is that on every new number entered eg for 1.75 it updates on the '1', then the '1.' then the '1.7', then the '1.75',
This seemed to work for me...
Code:
CDbl(Me.ControlName.Text)
 
are you talking abount Report here, since you mentioned Margin?
instead of changing the margin, change the Font size(smaller or normal) of the Textbox
on the Format Event of the report.
 
DBguy is right, of course!

PAPrice

is shorthand, if you will, for

PAPrice.Value

and since this is being done without you actually leaving the PAPrice Control...it has no Value, as yet...so you have to use the Text Property:

PAPrice.Text

Anytime you refer to PAPrice.

You probably also need to take into account the possibility that StandardCost could be Null (empty) when your end users enter the data in PAPrice.

Linq ;0)>
 
so it is not a Report:

Code:
Private Sub PAPrice_Change()
   If Len(Me.PAPrice.Text) > 0 Then
         Me.Margin = Val(Me.PAPrice.Text) - Nz(Me.StandardCost, 0) / Nz(Me.StandardCost, 1)
         Me.Margin.Enabled = False
   End If
End Sub
 
The change event runs once for EACH character typed into the control. Since you are doing arithmetic on the value, this makes no sense at all. Do the calculation in the PAPrice's AfterUpdate event so it happens only ONCE when the data entry is complete.
 

Users who are viewing this thread

Back
Top Bottom