473,385 Members | 1,344 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

problems rounding up

44
Hello - I am new at access and would greatly appreciate help. I have a textbox that lists salary. I need my report to show salary rounded up. ex: salary is $24,500.00. I want report to show 25,000. Is this possible. I have looked up info on function "ceiling" but no luck!!
May 10 '07 #1
14 1975
ADezii
8,834 Expert 8TB
Hello - I am new at access and would greatly appreciate help. I have a textbox that lists salary. I need my report to show salary rounded up. ex: salary is $24,500.00. I want report to show 25,000. Is this possible. I have looked up info on function "ceiling" but no luck!!
Here's a little Code Template I through together prior to bedtime. I'm sure you can play around with it and tailor it to your needs.
Expand|Select|Wrap|Line Numbers
  1. Public Function fRoundSalary(curSalary As Currency) As Long
  2.  
  3. 'Fix will truncate the Decimal portion of curSalary
  4. Select Case curSalary
  5.   Case 10000 To 99999
  6.     'Round to the 1000
  7.     fRoundSalary = CLng(Fix(curSalary) / 1000) * 1000
  8.   Case 100000 To 999999
  9.     'Round to the 10000
  10.     fRoundSalary = CLng(Fix(curSalary) / 10000) * 10000
  11.   Case Else
  12. End Select
  13. End Function
To Call this Function:
Expand|Select|Wrap|Line Numbers
  1. Debug.Print Format$(fRoundSalary(88499), "Currency")
  2. OUTPUT: $88,000.00
Expand|Select|Wrap|Line Numbers
  1. Debug.Print Format$(fRoundSalary(88501), "Currency")
  2. OUTPUT: $89,000.00
Expand|Select|Wrap|Line Numbers
  1. Debug.Print Format$(fRoundSalary(553499), "Currency")
  2. OUTPUT: $550,000.00
Expand|Select|Wrap|Line Numbers
  1. Debug.Print Format$(fRoundSalary(555501), "Currency")
  2. OUTPUT: $560,000.00
May 11 '07 #2
Zulema
44
Here's a little Code Template I through together prior to bedtime. I'm sure you can play around with it and tailor it to your needs.
Expand|Select|Wrap|Line Numbers
  1. Public Function fRoundSalary(curSalary As Currency) As Long
  2.  
  3. 'Fix will truncate the Decimal portion of curSalary
  4. Select Case curSalary
  5.   Case 10000 To 99999
  6.     'Round to the 1000
  7.     fRoundSalary = CLng(Fix(curSalary) / 1000) * 1000
  8.   Case 100000 To 999999
  9.     'Round to the 10000
  10.     fRoundSalary = CLng(Fix(curSalary) / 10000) * 10000
  11.   Case Else
  12. End Select
  13. End Function
To Call this Function:
Expand|Select|Wrap|Line Numbers
  1. Debug.Print Format$(fRoundSalary(88499), "Currency")
  2. OUTPUT: $88,000.00
Expand|Select|Wrap|Line Numbers
  1. Debug.Print Format$(fRoundSalary(88501), "Currency")
  2. OUTPUT: $89,000.00
Expand|Select|Wrap|Line Numbers
  1. Debug.Print Format$(fRoundSalary(553499), "Currency")
  2. OUTPUT: $550,000.00
Expand|Select|Wrap|Line Numbers
  1. Debug.Print Format$(fRoundSalary(555501), "Currency")
  2. OUTPUT: $560,000.00

Thanks for the feed back. Can you please tell me where i have to enter the codes. is it in the control that is supposed to display the output? Properties then code builder? I am very new to this....
May 13 '07 #3
ADezii
8,834 Expert 8TB
Thanks for the feed back. Can you please tell me where i have to enter the codes. is it in the control that is supposed to display the output? Properties then code builder? I am very new to this....
Enter this code in the Default Value row of of the Control that is suppopsed to display the results of the calculation. [txtTest] is the Field containing the value to be passsed to the Function
Expand|Select|Wrap|Line Numbers
  1. =fRoundSalary(Me![txtTest])
May 13 '07 #4
Zulema
44
Thanks, but I get #Name? in the Control Box.
May 14 '07 #5
ADezii
8,834 Expert 8TB
Thanks, but I get #Name? in the Control Box.
You must substitute your Field name in place of txtTest.
May 14 '07 #6
Zulema
44
You must substitute your Field name in place of txtTest.
I have =fRoundSalary([Me]![Salary]). It returns #Name? :{
May 14 '07 #7
Denburt
1,356 Expert 1GB
You need to place the first portion of aDezii's code in the VBA window (the module for that form or even a new module). Once you have done that it should work.

Expand|Select|Wrap|Line Numbers
  1. Public Function fRoundSalary(curSalary As Currency) As Long
  2.  
  3. 'Fix will truncate the Decimal portion of curSalary
  4. Select Case curSalary
  5.   Case 10000 To 99999
  6.     'Round to the 1000
  7.     fRoundSalary = CLng(Fix(curSalary) / 1000) * 1000
  8.   Case 100000 To 999999
  9.     'Round to the 10000
  10.     fRoundSalary = CLng(Fix(curSalary) / 10000) * 10000
  11.   Case Else
  12. End Select
  13. End Function
May 14 '07 #8
Zulema
44
You need to place the first portion of aDezii's code in the VBA window (the module for that form or even a new module). Once you have done that it should work.

Expand|Select|Wrap|Line Numbers
  1. Public Function fRoundSalary(curSalary As Currency) As Long
  2.  
  3. 'Fix will truncate the Decimal portion of curSalary
  4. Select Case curSalary
  5.   Case 10000 To 99999
  6.     'Round to the 1000
  7.     fRoundSalary = CLng(Fix(curSalary) / 1000) * 1000
  8.   Case 100000 To 999999
  9.     'Round to the 10000
  10.     fRoundSalary = CLng(Fix(curSalary) / 10000) * 10000
  11.   Case Else
  12. End Select
  13. End Function
I'm sorry I probably sound like an idiot to you guys! I placed the first portion of dezii's code in the form module, but it still doesn't work....:{{
May 14 '07 #9
Denburt
1,356 Expert 1GB
I'm sorry I probably sound like an idiot to you guys! I placed the first portion of dezii's code in the form module, but it still doesn't work....:{{

Interesting approach one I haven't used in a long time, but it seems to work only when I removed Me from the default value. You still might need to change up the function depending on the value range you are looking for.

Expand|Select|Wrap|Line Numbers
  1. =fRoundSalary([Salary])
May 15 '07 #10
ADezii
8,834 Expert 8TB
I'm sorry I probably sound like an idiot to you guys! I placed the first portion of dezii's code in the form module, but it still doesn't work....:{{
Place it in a Standard Code Module so it is accessible from anywhere within the Application. A Function really should not be declared Publically in a Form Module, it actually acts as a Method of the Form.
May 15 '07 #11
Zulema
44
Place it in a Standard Code Module so it is accessible from anywhere within the Application. A Function really should not be declared Publically in a Form Module, it actually acts as a Method of the Form.
I am still having trouble...:{ Field name that contains the value is Salary. Field name that should have the answer to the calculation is LifeSalary. I am writing the codes in the modules exactly like i see them in your replies. Please help.
May 21 '07 #12
Denburt
1,356 Expert 1GB
I am still having trouble...:{ Field name that contains the value is Salary. Field name that should have the answer to the calculation is LifeSalary. I am writing the codes in the modules exactly like i see them in your replies. Please help.
What exactly are you having trouble with?

If you enter a default value "=fRoundSalary([Salary])" in properties for the Lifesalary control then if the Salary Field will contain the results.

There are many approaches depending on your circumstances. I can see where the default value may not be sufficient such as if you enter the info into salary control then you need to update the LifeSalary control as well. In that case add an on update event to the Salary field and add the following to that event.

Expand|Select|Wrap|Line Numbers
  1. Me!LifeSalary=fRoundSalary([Salary])
Please provide any details relevant to your problem otherwise we can sit here and guess all day.
May 21 '07 #13
ADezii
8,834 Expert 8TB
I am still having trouble...:{ Field name that contains the value is Salary. Field name that should have the answer to the calculation is LifeSalary. I am writing the codes in the modules exactly like i see them in your replies. Please help.
  1. Make sure that the Procedure exists in a Standard Code Module.
    Expand|Select|Wrap|Line Numbers
    1. Public Function fRoundSalary(curSalary As Currency) As Long
    2.  
    3. 'Fix will truncate the Decimal portion of curSalary
    4. Select Case curSalary
    5.   Case 10000 To 99999
    6.     'Round to the 1000
    7.     fRoundSalary = CLng(Fix(curSalary) / 1000) * 1000
    8.   Case 100000 To 999999
    9.     'Round to the 10000
    10.     fRoundSalary = CLng(Fix(curSalary) / 10000) * 10000
    11.   Case Else
    12. End Select
    13. End Function
  2. Make sure that your Text Box 'Control Names' are LifeSalary and Salary.
  3. Enter =fRoundSalary(Me![Salary]) as the Default Value for the LifeSalary Text Box.
  4. Allow for the Case Else possibility within the Function (<10000 or >999999).
  5. If this still doesn't work, I'm honestly lost for an answer.
May 21 '07 #14
Zulema
44
  1. Make sure that the Procedure exists in a Standard Code Module.
    Expand|Select|Wrap|Line Numbers
    1. Public Function fRoundSalary(curSalary As Currency) As Long
    2.  
    3. 'Fix will truncate the Decimal portion of curSalary
    4. Select Case curSalary
    5.   Case 10000 To 99999
    6.     'Round to the 1000
    7.     fRoundSalary = CLng(Fix(curSalary) / 1000) * 1000
    8.   Case 100000 To 999999
    9.     'Round to the 10000
    10.     fRoundSalary = CLng(Fix(curSalary) / 10000) * 10000
    11.   Case Else
    12. End Select
    13. End Function
  2. Make sure that your Text Box 'Control Names' are LifeSalary and Salary.
  3. Enter =fRoundSalary(Me![Salary]) as the Default Value for the LifeSalary Text Box.
  4. Allow for the Case Else possibility within the Function (<10000 or >999999).
  5. If this still doesn't work, I'm honestly lost for an answer.
Thank you! The text box Life Salary is calculating now, but how can i fix it to round up. On a salary of $29,500, it needs to calculate $30,000.
May 21 '07 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: spebola | last post by:
I am using vb.net 2003 professional and I get the following results when using the round method: dim Amount as decimal = 180.255 Amount = Amount.Round(Amount, 2) Amount now contains 180.25. ...
8
by: Zorpiedoman | last post by:
Howcome: Dim D as decimal = .5D msgbox d.Round(D, 0) this returns "0" Now when I went to school .5 rounds UP to 1 not DOWN to zero?????!!! Documentation says this, but what the heck are...
2
by: Jiri Nemec | last post by:
Hello all, I have got one table with rounding values, table contains prices and round types. id price_from price_to rounding 1 0 1500 0.1 2 1500 ...
27
by: G Patel | last post by:
Hello, I'm having trouble with floating point problems. I'm trying to write a function that calculates the distance between two cartesian points (integer coordinates). I have the function...
11
by: cj | last post by:
Lets assume all calculations are done with decimal data types so things are as precise as possible. When it comes to the final rounding to cut a check to pay dividends for example in VB rounding...
4
by: AdINo | last post by:
I'm having problems with rounding numbers pls help me out this is the program instruction that i wrote x = 420.30 * 0.15 y = 420.30 - x i print the y out in .2lf format ...
18
by: jdrott1 | last post by:
i'm trying to round my currency string to end in 9. it's for a pricing application. this is the function i'm using to get the item in currency: FormatCurrency(BoxCost, , , , TriState.True) if...
4
by: =?Utf-8?B?UmVuZQ==?= | last post by:
Hello everyone I have a problem with Math.Round, it´s ocurring some strange: Math.Round(12.985) = 12.98, it´s wrong. It should be: 12.99 Why?? What is the problem? Help ME !!!!
206
by: md | last post by:
Hi Does any body know, how to round a double value with a specific number of digits after the decimal points? A function like this: RoundMyDouble (double &value, short numberOfPrecisions) ...
20
by: jacob navia | last post by:
Hi "How can I round a number to x decimal places" ? This question keeps appearing. I would propose the following solution #include <float.h> #include <math.h>
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.