Results 1 to 4 of 4
  1. #1
    MatthewGrace is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2013
    Posts
    163

    Overflow Error on a Double datatype

    Hello all, thank you for considering my question.


    I wrote a function for calculating Freight class. It’s very easy: multiply inches of Length*Width*Height and divide that number by 1728. That’s your Cubic Footage. Then, divide Weight by that number.

    As you can see, I defined the L/W/H arguments for my function as Integers, which I understand has an upper limit around 32,000 and cannot contain a decimal place. No big deal I thought. This function will always be called where L/W/H are supplied as low whole numbers. As an example, 65x40x14. See? Low, whole numbers.

    Weirdly, my function gives me an “Overflow” error. The highlighted offending line is ultimately getting stored into a Double datatype. I’d have figured that Double was beyond sufficient to contain the result of this math.

    But the part that is most perplexing is how I resolved the error, and this is what I want you to comment on: I simply went into the topmost line and changed the datatype of all 4 arguments (nLength… etc) FROM integers TO doubles. All of a sudden it works perfect!

    But why? The 4 arguments, back when I called them Integers, never once contained a decimal value or were challenged by being too high or low. Their values are absolutely in range. Furthermore, the dblDensity variable is already a double and should be able to handle these numbers easily. In the example you see crashing in the screenshot below, the value of dblDensity would be 77.5 not exactly a challenge for a double datatype.

    So what is the significance of changing the 4 integer arguments into double datatype that it suddenly works???

    Afterthought: I checked this function again later, leaving out the Weight division. It still errors. It’s something about the Density. See the MsgBox in the line below? It should read something like 14.xxxxxxxxx many decimal places. But since storing this value should have nothing to do with the integer datatypes supplied for the equation, I don’t see why this would cause an overflow.

    Click image for larger version. 

Name:	Overflow Error.jpg 
Views:	9 
Size:	109.4 KB 
ID:	43470

  2. #2
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,358
    IIRC Access will treat a calculation as the same data type as the inputs (in your case integer). Your calculation exceeds 32000 before division, hence overflow. At the least, I would have used longs for that very reason.

    EDIT- you can test that theory bu substituting inputs that when multiplied, do not exceed 32000.
    Last edited by Micron; 11-19-2020 at 04:00 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    MatthewGrace is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2013
    Posts
    163
    Interesting. I just always assumed that since the result of the equation was being stored as a double, then that double is what would produce the overflow error.


    Thank you Micron.

  4. #4
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,358
    You're welcome. Maybe think of it this way. If you have a quart in a quart container and you try to add another quart to it, you have overflow. If you have a quart in a gallon container and add a quart, it fits and you can pass it on. I find that there is a lot of Access issues caused by us seeing the forest only (end result) and not the trees (immediate results). When I say that I'm thinking of multi line declarations (Dim statements) too.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 2
    Last Post: 07-13-2016, 08:28 AM
  2. Replies: 3
    Last Post: 07-18-2015, 05:02 PM
  3. Criteria datatype error???
    By GraeagleBill in forum Programming
    Replies: 12
    Last Post: 05-04-2015, 11:01 AM
  4. DLookUp DataType Mismatch Error
    By theosgood in forum Programming
    Replies: 2
    Last Post: 10-29-2013, 10:04 AM
  5. confusing datatype error issue
    By TheShabz in forum Queries
    Replies: 5
    Last Post: 10-11-2010, 05:14 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