Expression in a form

  • Thread starter quinto via AccessMonster.com
  • Start date
Q

quinto via AccessMonster.com

I have a simple expression in a form
Field21: =[EndMiles]-[StartMiles]

I would like to see the results as soon as I tab away from the field but it
is not updating ulness I close and open the form.
I am sure there is a solution to this
Can anyone help
Thanks

Quinto
 
L

Linq Adams via AccessMonster.com

Don't know where you have your code, but from your post I assume it's
somewhere in your form. There's other ways to do this, but here's two subs
that will do the job:

Private Sub EndMiles_AfterUpdate()
If Not IsNull(Me.StartMiles) Then
Me.Field21 = Me.EndMiles - Me.StartMiles
End If
End Sub

Private Sub StartMiles_AfterUpdate()
If Not IsNull(Me.EndMiles) Then
Me.Field21 = Me.EndMiles - Me.StartMiles
End If
End Sub

When you exit either the StartMiles or EndMiles textbox, if the other textbox
is filled in, the total mileage (Field21) will automatically be populated.


Another way to do this, if your form were based on a query, would be to have
a calculated field in your query, very similar to your posted code, leaving
out only the equal sign:

TotalMiles:[EndMiles]-[StartMiles]

Then, in your form, use TotalMiles as the Control Source for your textbox
Field21.
 
D

Douglas J. Steele

I'm unable to replicate your problem: my calculated field updates as soon as
I update EndMiles or StartMiles.
 
K

Klatuu

The value in Field21 will update whenever [EndMiles] or [StartMiles] is
changed by a user entering the values on the form; however, if either of the
values is changed programmatically, Field21 will not change. You can cause
it to change by using the Recalc method. Recalc does not appy to a control,
but to the form, so where ever you have code that modifies either of the
values, follow the calculation with
Me.Recalc
 
Q

quinto via AccessMonster.com

Thank you all

I moved the expression to the Queery and it works fine.

Quinto
The value in Field21 will update whenever [EndMiles] or [StartMiles] is
changed by a user entering the values on the form; however, if either of the
values is changed programmatically, Field21 will not change. You can cause
it to change by using the Recalc method. Recalc does not appy to a control,
but to the form, so where ever you have code that modifies either of the
values, follow the calculation with
Me.Recalc
I have a simple expression in a form
Field21: =[EndMiles]-[StartMiles]
[quoted text clipped - 6 lines]
 

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

Top