Question about Change event

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi - I have a textbox [txtResidualValue] with a datasource that is calculated
based on other textbox values, one of which is [txtMSRP]. If changes in any
of the textboxes cause the calculated value in [txtResidualValue] to drop
below 25% of the value in [txtMSRP] then I want to flash a messagebox. Can
this be done with code in [txtResidualValue] or does it have to be done in
the afterupdate event of each of the controls affecting [txtResidualValue]?

Thanks!
 
The change event is not a good thing to use in most cases. It fires for
every change. Than means, if you type in F, it fires. Then you type in O,
it fires, Then you type in O, it fires. So, each new character or deletion
of a character causes it to fire.

Now, to your specific problem. It can't be done in any txtResidualValue
event. Non of them will fire. My solution would be to put a sub in the
General section of the form module and call it in the After Update event of
each control that is used in the calculation. The sample code below assumes
that the calculation will only take effect if all the participating controls
have a value:

If IsNull(Me.txtMSRP) Then
Exit Sub
End If

If IsNull(Me.txtSomethingElse) Then
Exit Sub
End If

Me.txtResidualValue = 'The Calculation goes here

If Me.txtResidualValue < 25% Then 'The compare will depend on data format
MsgBox "This Junker Ain't Worth Nothing"
End If
 
This is as I suspected. I am currently coding all the other controls. Thanks!
--
Gary in Michigan, USA


Klatuu said:
The change event is not a good thing to use in most cases. It fires for
every change. Than means, if you type in F, it fires. Then you type in O,
it fires, Then you type in O, it fires. So, each new character or deletion
of a character causes it to fire.

Now, to your specific problem. It can't be done in any txtResidualValue
event. Non of them will fire. My solution would be to put a sub in the
General section of the form module and call it in the After Update event of
each control that is used in the calculation. The sample code below assumes
that the calculation will only take effect if all the participating controls
have a value:

If IsNull(Me.txtMSRP) Then
Exit Sub
End If

If IsNull(Me.txtSomethingElse) Then
Exit Sub
End If

Me.txtResidualValue = 'The Calculation goes here

If Me.txtResidualValue < 25% Then 'The compare will depend on data format
MsgBox "This Junker Ain't Worth Nothing"
End If
GaryS said:
Hi - I have a textbox [txtResidualValue] with a datasource that is calculated
based on other textbox values, one of which is [txtMSRP]. If changes in any
of the textboxes cause the calculated value in [txtResidualValue] to drop
below 25% of the value in [txtMSRP] then I want to flash a messagebox. Can
this be done with code in [txtResidualValue] or does it have to be done in
the afterupdate event of each of the controls affecting [txtResidualValue]?

Thanks!
 
Gary,

If the control source of txtResidualValue has a function in it (=[txtMSRP] +
[txtSomeOtherfield] - [txtAThirdField]) that references the other text
boxes, it will automatically update whenever any of the other controls are
updated, so you don't have to create a function or put any code in the
afterupdate or change event of the other controls.

Then, I think I would go about this by setting a conditional format on the
txtResidualValue control. Set the conditional format as an expression and
type [txtResidualValue] < .75 * [txtMSRP], then set the background to red or
something like that, as soon as the form loads, it will compute whether this
value is below the 75%, and when you change the value of any of the other
controls that affect the residual value, it will also recompute and change
that control to red.

HTH
Dale
 
Dale,

Yes, txtResidualValue does have an iif satement as it's control source and
does change automatically. I just wanted to be able to run some other code
if it drops below25% of MSRP. The conditional formatting would help, but is
that available in A2K for a text control? I don't see it. Thanks for your
help.
--
Gary in Michigan, USA


Dale Fye said:
Gary,

If the control source of txtResidualValue has a function in it (=[txtMSRP] +
[txtSomeOtherfield] - [txtAThirdField]) that references the other text
boxes, it will automatically update whenever any of the other controls are
updated, so you don't have to create a function or put any code in the
afterupdate or change event of the other controls.

Then, I think I would go about this by setting a conditional format on the
txtResidualValue control. Set the conditional format as an expression and
type [txtResidualValue] < .75 * [txtMSRP], then set the background to red or
something like that, as soon as the form loads, it will compute whether this
value is below the 75%, and when you change the value of any of the other
controls that affect the residual value, it will also recompute and change
that control to red.

HTH
Dale

GaryS said:
Hi - I have a textbox [txtResidualValue] with a datasource that is
calculated
based on other textbox values, one of which is [txtMSRP]. If changes in
any
of the textboxes cause the calculated value in [txtResidualValue] to drop
below 25% of the value in [txtMSRP] then I want to flash a messagebox.
Can
this be done with code in [txtResidualValue] or does it have to be done in
the afterupdate event of each of the controls affecting
[txtResidualValue]?

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top