Entering Percentages

  • Thread starter Thread starter Joe Williams
  • Start date Start date
J

Joe Williams

How do I set up a field to enter a percentage (example 25) and have it
stored in the table as .25? Everything I try (setting format int eh table
with percentage, etc) still makes you enter the number as .25 in the field
rather than just entering 25 and having it store it properly. Am I missing
something?

Thanks

- joe
 
Paste the function below into a standard module.

Then set the AfterUpdate event procedure of your control to:
Call MakePercent(Me.XXXX)
where XXXX represents the name of the control.

The function looks for the % sign in the field, and if the user did not type
one, divides the entry by 100.


Public Function MakePercent(ctl As Control)
On Error GoTo Err_Handler
'Purpose: Treat as percent

If InStr(ctl.Text, "%") = 0 Then
ctl = ctl / 100
End If

Exit_Handler:
Exit Function

Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description
Resume Exit_Handler
End Function
 
Back
Top