Forum Discussion
Access_Jim
Jul 28, 2024Copper Contributor
Mysterious Overflow Error
This Access VBA code is giving me an overflow error. What am I doing wrong? Dim chunkSize As Long chunkSize = 320 * 1024 Also, I tried changing chunkSize to a Double, but got the same ove...
- Jul 29, 2024
Hi,
You are not the first to wonder about the VBA behaviour to "coerce" numbers into an integer. Have a look at the very similar example in the error documentation: Overflow (Error 6)
Servus
Karl
****************
Access News, Forever, DevCon
Access-Entwickler-Konferenz AEK - 19./20.10. Nürnberg
Access_Jim
Jul 28, 2024Copper Contributor
It is a new .accdb. I found that when I reduce it to 30 * 1024, it no longer throws the error. But it seems like datatype Long should be able to handle 320 * 1024
George_Hepworth
Jul 28, 2024Silver Contributor
You can get the specs for Access datatypes from these articles:
https://support.microsoft.com/en-us/office/data-types-for-access-desktop-databases-df2b83ba-cef6-436d-b679-3418f622e482
https://support.microsoft.com/en-us/office/set-the-field-size-ba65e5a7-2e6f-4737-8e72-36b93f966a33
A Long Integer can be from -2,147,483,648 to +2,147,483,647. Storage requirement is four bytes.
320 * 1024 = 327,680
That's well within the range.
And Integer, on the other hand, can be from -32,768 to +32,767. Storage requirement is two bytes.
I wonder if you are actually working with an Integer, not a Long Integer, in this context. Please validate that. I know you showed the variable dimmed as a Long, but this sure smells like an integer problem.
- Access_JimJul 28, 2024Copper ContributorI agree, it is behaving like an Integer data type. I will work around this. Thank you for your assistance.