Round Function

  • Thread starter Thread starter alex
  • Start date Start date
A

alex

Hello,

Can someone help with the following code:

I'm trying to return a value to a txtbox control using this
procedure...

Private Sub Hours_BeforeUpdate(Cancel As Integer)

Me.Hours = Round(4 * [Hours], 0) / 4

End Sub

The [Hours] field has a datatype of single.

I want the procedure to force any value to round to the nearest
quarter; e.g., 1.3 becomes 1.25; .9 becomes 1; etc.

Can the function be inside the procedure (like above)? If so, do I
have to pass its value to something?

Should the round function be in its own function procedure?

Thanks,
alex
 
Will not you have a circular reference ( Hours -- Hours )?
Maybe this --
Me.Hours_1 = (([Hours]*4)\1)/4
 
Hi Alex

The problem is the event you are using.

In BeforeUpdate you can validate the value and cancel the update or even
undo the change, but you may not explicitly change the value.

Use AfterUpdate instead.
 
Hi Alex

The problem is the event you are using.

In BeforeUpdate you can validate the value and cancel the update or even
undo the change, but you may not explicitly change the value.

Use AfterUpdate instead.

--
Good Luck  :-)

Graham Mandeno [Access MVP]
Auckland, New Zealand




Can someone help with the following code:
I'm trying to return a value to a txtbox control using this
procedure...
Private Sub Hours_BeforeUpdate(Cancel As Integer)
   Me.Hours = Round(4 * [Hours], 0) / 4
The [Hours] field has a datatype of single.
I want the procedure to force any value to round to the nearest
quarter; e.g., 1.3 becomes 1.25; .9 becomes 1; etc.
Can the function be inside the procedure (like above)?  If so, do I
have to pass its value to something?
Should the round function be in its own function procedure?
Thanks,
alex- Hide quoted text -

- Show quoted text -

Graham,
Worked like a charm. Many thanks.
alex
 
Back
Top