Event from Calculated Control

G

Guest

Can someone explain why this isn't working and what I need to do to make it
work. I have a form with three fields that need users to input a number value
and a fourth field on the same form which calculates the average of the three
values the user inputs. This works fine but I want a message box to appear
when the calculated average in the fourth field exceeds a certain value and I
can't get this to work - BeforeUpdate, AfterUpdate, Change won't trigger my
VBA MsgBox code even though the calculated average has exceeded the limit I
set.
TIA
 
B

Brendan Reynolds

You need to do the check in the AfterUpdate events of the *other* three
controls, the ones that accept user input. You may also want to add it to
the Current event procedure of the form, so that the control is updated when
browsing through records. Rather than repeating code in multiple event
procedures, put the common code into a procedure or function, and call that
procedure or function from the event procedures.
 
R

Rick Brandt

Alan said:
Can someone explain why this isn't working and what I need to do to
make it work. I have a form with three fields that need users to
input a number value and a fourth field on the same form which
calculates the average of the three values the user inputs. This
works fine but I want a message box to appear when the calculated
average in the fourth field exceeds a certain value and I can't get
this to work - BeforeUpdate, AfterUpdate, Change won't trigger my VBA
MsgBox code even though the calculated average has exceeded the limit
I set.
TIA

You would need that to be in the AfterUpdate event of all three TextBoxes
that the user types in. The box with the calculation does not have any
events fire just because its calculation result changes.
 
G

Guest

Brendan Reynolds said:
...Rather than repeating code in multiple event
procedures, put the common code into a procedure or function, and call that
procedure or function from the event procedures.

I'd like to see an example of that approach. Northwind?
 
B

Brendan Reynolds

I'm not intimately familiar with Northwind. It is certainly quite likely
that there is an example in there somewhere, but I could not say for sure.
 
B

Bill Mosca, MS Access MVP

Taking it one step further, if you use the before update events, you will
have a way to cancel should you need to.
 
G

Guest

Thanks everyone. Problem solved.
Alan

Bill Mosca said:
Taking it one step further, if you use the before update events, you will
have a way to cancel should you need to.
 

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