Public Function for Round up Numbers

S

sandrao

Rather that placing the code Round([MyField],2) in all the currency
fields that may go the 0.000 three places would a Public function
resolve that problem. and If so How would the code be written?
 
A

Allen Browne

No. You need to use Round() in the AfterUpdate event procedure of any
control where you think the user might enter more than 2 digits.

Or use Round() around the expression if you are assigning values to a field,
or around an expresion in your query.

Use an Update query to fix up any existing fields that might already contain
unrounded values.
 
K

Ken Sheridan

You could for data entry by users. Add the following to a standard module:

Public Function RoundCurrency(frm As Form)

Dim ctrl As Control

Set ctrl = frm.ActiveControl
ctrl = Round(ctrl, 2)

End Function

And call it as the AfterUpdate event property of each control:

=RoundCurrency([Form])

But as Allen says, if assigning values call the Round function in the VBA
code or SQL statement.

Ken Sheridan
Stafford, England
 
Top