Forum Discussion
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 overflow error.
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
5 Replies
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- peiyezhuBronze ContributorIt looks fine.
Have you testes these VBA in a new .accdb or Excel VBA?- Access_JimCopper ContributorIt 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_HepworthSilver 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-3418f622e482https://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.