SOLVED

Mysterious Overflow Error

Copper Contributor

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.

 

 

 

5 Replies
It looks fine.
Have you testes these VBA in a new .accdb or Excel VBA?
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

@Access_Jim 

 

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-436...

 

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.

I agree, it is behaving like an Integer data type. I will work around this. Thank you for your assistance.
best response confirmed by Access_Jim (Copper Contributor)
Solution

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

1 best response

Accepted Solutions
best response confirmed by Access_Jim (Copper Contributor)
Solution

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

View solution in original post