Public Function for Round up Numbers

  • Thread starter Thread starter sandrao
  • Start date Start date
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?
 
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.
 
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
 

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