Results 1 to 13 of 13
  1. #1
    Jerseynjphillypa is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Apr 2012
    Posts
    83

    Fixing #Num! error and rounding when Inserting text box with formula

    Here is the formula that I inserted within a text box to do some calculation for me

    =Sum([Used])/Sum([Total])*100

    How would I remove the #Num! error

    Also how can I round to 2 decimal places, for example 94.7368421052632 to 94.74.
    Last edited by Jerseynjphillypa; 04-16-2012 at 01:06 PM.

  2. #2
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You will have to provide some additional details about your form and your tables. Is the form on which the texbox is located a bound form (i.e. bound to a table or query)? What other controls do you have on the form? Where are you putting the text box on the form-in the detail section or the form footer? From where is the [Total] value coming, another table?

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Quote Originally Posted by Jerseynjphillypa View Post
    Here is the formula that I inserted within a text box to do some calculation for me

    =Sum([Used])/Sum([Total])*100

    How would I remove the #Num! error
    What are you tring to calculate. Just the current record, or all records?


    Also how can I round to 2 decimal places, for example 94.7368421052632 to 94.74.
    Set the Format property to Fixed
    Set the Decimal Places property to 2
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    Jerseynjphillypa is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Apr 2012
    Posts
    83
    Quote Originally Posted by jzwp11 View Post
    You will have to provide some additional details about your form and your tables. Is the form on which the texbox is located a bound form (i.e. bound to a table or query)? What other controls do you have on the form? Where are you putting the text box on the form-in the detail section or the form footer? From where is the [Total] value coming, another table?
    My report is coming from one table I created using a Query. I used the Report Wizard, and placed the the text box with my formula in the Footer Section.

  5. #5
    Jerseynjphillypa is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Apr 2012
    Posts
    83
    Quote Originally Posted by Bob Fitz View Post
    What are you tring to calculate. Just the current record, or all records?



    Set the Format property to Fixed
    Set the Decimal Places property to 2
    I am trying to calculate the average based on all the records that have the same item name from my table.


    Also thanks for helping with my formatting issue with the decimal places.

  6. #6
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    If you are trying to calculate the average based on the item name, it sounds like you need to add a group level based on item name to your report. I created a real simple database with a report using the report wizard; please see the attached database.
    Attached Files Attached Files

  7. #7
    Jerseynjphillypa is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Apr 2012
    Posts
    83
    Thanks for the the jzwp11, the grouping helped
    But sometimes the field is blank and there is no data for the item. Hence i get the error #N/A!. I want to know how I can remove this error.

  8. #8
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You can filter the query on which the report is based to only show items that have the data. What is the SQL text of your query?

  9. #9
    Jerseynjphillypa is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Apr 2012
    Posts
    83
    I can provide you the query but when I created the query blank and 0 can be valid answer in the table. So that's why i am trying to figure out a way to remove the #Num error within the report section only

  10. #10
    Join Date
    Apr 2012
    Location
    Los Angeles
    Posts
    75
    In your query you can use the function =nz(fieldname). nz converts null values to zeros in the result.

  11. #11
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    I did not ask before, buy where are you getting the #Num and or #N/A? In one of the summary controls in the group footer or in the detail section of the report?

  12. #12
    Join Date
    Apr 2012
    Location
    Los Angeles
    Posts
    75
    To avoid divide by zero errors you need to do something like this:
    =Iif (nz(Sum([Total])) = 0,0, Sum([Used])/Sum([Total])*100)

  13. #13
    bsftms is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Posts
    1
    That's because there's a Null value or a formula that result in null (error)
    So, I prefer using solution below :
    1. Make new module
    2. Make a custom public function, use this code :

    Public Function CustomDevide(ByVal x As Variant, ByVal y As Variant) As Variant
    On Error GoTo ErrorHandler
    Dim tmp As Variant
    tmp = x / y
    If IsNull(tmp) Then tmp = 0
    CustomDevide= tmp
    ErrorExit:
    Exit Function
    ErrorHandler:
    CustomDevide = 0
    Resume ErrorExit
    End Function

    3. use it as formula in your report like this

    =CustomDevide(Sum([Used]);Sum([Total]))*100
    4. That's it, sorry for my terrible english.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Fixing run-time error 3049
    By kthakk4 in forum Programming
    Replies: 1
    Last Post: 09-30-2011, 07:37 AM
  2. formula in text box problem
    By kwooten in forum Reports
    Replies: 7
    Last Post: 09-12-2011, 08:19 AM
  3. Inserting text from a function
    By Mclaren in forum Programming
    Replies: 3
    Last Post: 03-08-2011, 01:29 PM
  4. Stop text box from rounding decimals
    By Deutz in forum Access
    Replies: 1
    Last Post: 02-17-2011, 07:32 PM
  5. need a little help fixing an SQL error...
    By markjkubicki in forum Queries
    Replies: 3
    Last Post: 08-04-2010, 06:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums