Change rounding rule in ms access

  • Thread starter Thread starter nivs
  • Start date Start date
N

nivs

Hi,

I have a price field of type Number.
I need the following validation rules to be set up.
If (decimal part of price) < 50
then round (decimal part of price) to 45
if (decimal part of price) >50 & < 75
then round (decimal part of price) to 65
if (decimal part of price) >75 & < 100
then round (decimal part of price) to 90

How should i set this rule.Where should i set this rule.
Please suggest some solutions.
 
Create a Function:
Function Rond(Num)
Dim moduloo, Num As Single
moduloo = Num * 100 Mod 100
Select Case moduloo
Case Is <= 50
Rond = Int(Num) + 0.45
Case 50 To 75
Rond = Int(Num) + 0.65
Case Is > 75
Rond = Int(Num) + 0.9
End Select
End Function

Use this function just like you would use the normal Round function, but
without the decimal places, e.g.
NewPrice:Rond(OldPrice)
 
Put it in the Before Update event of the control where price is entered:

dim sngDecimalPart as Single
dim sngWholePart as Single

sngWholePart = Int(Me.Price)
sngDecimalPart = Me.Price - Int(Me.Price)
Select Case sngDecimalPart * 100
Case is < 50
sngDecimalPart = .45
Case 51 to 75
sngDecimalPart = .65
Case 76 to 100
sngDecimalPart = .90
End Select
Me.Price = sngWholePart + sngDecimalPart
 
I'm sorry. Place it in a field of the query of the table that has the old
price
Hi jahoobob
Where should i use this NewPrice:Rond(OldPrice)??
Can u pls tell me tht
Create a Function:
Function Rond(Num)
[quoted text clipped - 27 lines]
 
SELECT Rond([OldPrice]) AS NewPrice
FROM [tblYourTable];

hi klattu
how am to put this before update event.I update using sql query.
Put it in the Before Update event of the control where price is entered:
[quoted text clipped - 26 lines]
 
Back
Top