Hardware-wise, that 40K value will easily fit into a LONG, which gives you about a 2.147 billion limit as a signed long integer. If you have a "native" Access back-end file, or if the app is a single Access .MDB or .ACCDB stand-alone file, you cannot define an unsigned integer. (If the back end is an SQL Server or another active SQL engine, all bets are off.) However, at some point you appear to be running into a case where an "ordinary" (word) INTEGER is the recipient of a LONG value. As noted by others, you reach a hardware limit for INTEGER at 32767, the largest signed value a word integer can hold. Adding 1 to 32767 in an INTEGER flips the sign bit due to an overflow.
Inside any VBA expression there is an automatic feature (called LET coercion) that will adjust data sizes of the expression elements to match what is needed to keep the expression from blowing up on you. However, there are cases where this coercion effect doesn't apply. The three biggest cases are
(1) assigning the value of a LONG (or floating-point) expression to an INTEGER (i.e. INTEGER = LONG expression)
(2) Inside a subroutine, assigning a LONG return value to a subroutine parameter that was defined as an INTEGER BY REF
(3) Returning a LONG value for a function declared to return an INTEGER.
Catching a STACK OVERFLOW message adds a little spice to this recipe. You normally cannot directly reference the hardware Stack Pointer so this error has to be triggered by an indirect effect. Do you attempt anything recursive in your code that would be based on that variable that you said was getting 40K as its content?
What is MORE interesting is that storing a number >32767 in an INTEGER should have triggered run-time error 6, "Overflow" - which would have occurred BEFORE whatever triggered that "Stack Overflow" error you mentioned. I checked the VBA Language Reference (2014 version) and it does not say what value would be stored in that case (LONG trucated to INTEGER? set to 32767? set to 0? VBA Language Reference doesn't say). But you would get no value at all unless you had an ON ERROR RESUME NEXT in your code.