Round off a Number Field

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I have a form where I input numbers. If the number inputed is greater that
99.99 I want to found off to the nearest whole number. What would the code
be for doing this and in which event should I place the code? I've tried
various things, none of which worked.

Thanks
 
Hi,
I have a form where I input numbers. If the number inputed is greater that
99.99 I want to found off to the nearest whole number. What would the code
be for doing this and in which event should I place the code? I've tried
various things, none of which worked.

Thanks

You can use the AfterUpdate event of the textbox in which you're entering the
number (confusingly enough, the BeforeUpdate event doesn't work but
AfterUpdate does):

Private Sub txtMyTextbox_AfterUpdate()
If Me!txtMyTextbox > 99.99 Then
Me!txtMyTextbox = Round(Me!txtMyTextbox, 0)
End If
End Sub

John W. Vinson [MVP]
 
Maybe it is better to place that in your query if that's the recordsource.
You could use something like:

iif([number]>99.99;cint(number);number)

cint will make the number a whole number.
 
Back
Top