Round Function

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
 
K

KARL DEWEY

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

Graham Mandeno

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.
 
A

alex

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
 

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

Top