Results 1 to 9 of 9
  1. #1
    TOMMY.MYERS668's Avatar
    TOMMY.MYERS668 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2013
    Location
    West Virginia
    Posts
    77

    Calculation in vba not rounding up.

    Ok I'm wearing this forum out.. That's what i get for trying to reteach myself vba and access 11 years since the last time i used it.

    I have a calculation in access that very seldom returns a whole number but I need it to round up to the next whole number if it does not. I have searched for other posts on here and come up with some of it I think but It doesnt seem to be working. It must allways round up tho rounding down will hose what im trying to accomplish.

    So far I have this jewel:
    Private Sub QUOTAS_AfterUpdate()
    Dim instructorsreq As Long
    instructorsreq = Me![QUOTAS] \ Me![ISR]


    If instructorsreq = Int(instructorsreq) Then
    Me![INSTRUCTORS REQUIRED] = instructorsreq
    Else
    Me![INSTRUCTORS REQUIRED] = Int(instructorsreq) + 1
    End If

    End Sub

    Ive seen some post about negative intigers but im not quite understanding what there doing - Its been along week. any ideas?
    Last edited by TOMMY.MYERS668; 02-08-2013 at 11:39 AM. Reason: additional info

  2. #2
    alcapps is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Jan 2012
    Posts
    292
    there is a
    Math.Round(instructorsreq,2)

    function round()

    are you trying to get the next integer value up from the value you return form you calculation?
    or a true rounding to a decimal place.

  3. #3
    TOMMY.MYERS668's Avatar
    TOMMY.MYERS668 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2013
    Location
    West Virginia
    Posts
    77
    basically i need to know how many instructors are required to be scheduled for a clas- so if my instructor to student ration ins 1 instructor : 12 students and my quota for the class is 23 Is should say instructors required are 2 - it would only say 1 if my quota was 12 or less. so basically yes to the next highest integer.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Conceptually what you're doing is fine. It breaks down because of:

    Dim instructorsreq As Long

    Long will only hold the integer portion, no decimal. I'd probably use Currency to avoid floating point issues.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    TOMMY.MYERS668's Avatar
    TOMMY.MYERS668 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2013
    Location
    West Virginia
    Posts
    77
    I'll give it a shot and let you know real quick thanks.

  6. #6
    TOMMY.MYERS668's Avatar
    TOMMY.MYERS668 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2013
    Location
    West Virginia
    Posts
    77
    ok dim'd as currency still is not giving me the next integer up.... now current code is :
    Private Sub QUOTAS_AfterUpdate()
    Dim instructorsreq As Currency
    instructorsreq = Me![QUOTAS] \ Me![ISR]
    If instructorsreq = Int(instructorsreq) Then
    Me![INSTRUCTORS REQUIRED] = instructorsreq
    Else
    Me![INSTRUCTORS REQUIRED] = Int(instructorsreq) + 1
    End If

    End Sub

    is it maybe something in the way I have the actual instructors required box in access formatted?

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Try

    instructorsreq = Me![QUOTAS] / Me![ISR]
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    TOMMY.MYERS668's Avatar
    TOMMY.MYERS668 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2013
    Location
    West Virginia
    Posts
    77
    Ok changing the from backslash to forward slash worked!. Is there any particular reason why it worked?? does access perform a diffent function for different slashes? but at anyrate your awesome!

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Yes, the back slash is different. From an MS site, it will:

    Round both numbers to integers, divide the first number by the second number, and then truncate the result to an integer.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Calculation Field in table vs Query calculation
    By Leonidsg in forum Database Design
    Replies: 18
    Last Post: 02-28-2013, 09:38 PM
  2. rounding down
    By markcranmer in forum Queries
    Replies: 1
    Last Post: 10-11-2011, 09:43 AM
  3. Rounding
    By BLD21 in forum Reports
    Replies: 5
    Last Post: 06-20-2011, 01:06 PM
  4. Rounding problem
    By jgelpi16 in forum Queries
    Replies: 1
    Last Post: 04-06-2010, 10:27 AM
  5. Rounding off
    By Alex Motilal in forum Access
    Replies: 4
    Last Post: 12-20-2009, 12:47 PM

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