That both arguments execute, and identically, is astonishing.
Or not. I now refer to the VBA Language Specification v20140424,
5.6.9.3 Arithmetic Operators and
5.6.9.3.2 + Operator which present tables of compatible data types and their eventual data type after "LET COERCION" - the practice of converting different-sized data types to a data type that holds everything.
The order of evaluation for
Eval(1+1) is that VBA sees a function (doesn't care what it is quite yet) AND it sees an actual argument based on a literal constant expression. VBA knows constant expressions. So it evaluates
1+1 BEFORE calling Eval() and gets
2, after which it executes
Eval(2). And of course, you get back
2 for that case. This action is based on the general rule that you evaluate parenthetical expressions from the inside out, and in that context,
1+1 is a parenthetical expression.
For
Eval("1+1") you have a string expression as a simple actual argument, and since it is a quoted constant string, VBA just passes in the literal string.
Eval("1+1") gets executed and the evaluation code uses LET COERCION to see if that string could have been a text-based constant numeric expression, which in this case it very well could be. Therefore, in this quoted case, Eval() uses LET COERCION to convert the constant string (because that is what
"1+1" is) to get
1+1 (NOT strings after two coercions) and then computes
2, which it returns. They get the same results, which really ISN'T that astonishing.
But THEN... There is the case of
Eval("1" + "1") which uses the ambiguous "+" sign, which for strings CAN mean "concatenate." You have an expression inside parentheses with a viable operator and two numeric-constant strings. Most important... an expression with two strings separated by an operator that works on strings. So the concatenation occurs first (before Eval is called) because VBA does constant expressions from inner parentheses first.
"1"+"1" concatenates to
"11", after which
Eval("11") is what gets executed. Eval() checks whether that is a digit string - which it IS - and
11 gets returned.
You originally wanted to use EVAL on an argument like Eval( "con" & strStem & "Bar" ) - which according to the rules, would be processed by VBA to do the concatenation BEFORE calling Eval(). So if strStem is "Foo" you would be calling
Eval( "conFooBar" ) - and you cannot find a value for that. The link below is to Microsoft Support's article on Eval().
support.microsoft.com
In this article, there are discussions regarding evaluation of strings.
The stringexpr argument must evaluate to a string or numeric value; it can't evaluate to a Microsoft Access object.
I can't get a closed definition of where CONST values are stored, other than that they are stored within the compiled code. Part of the problem is that Access is not open source, so we don't know where things actually get stored. Given that VBA is compiled to pseudo-code, it is possible that the constant ISN'T treated as a variable after all. Asking Google on a far-out hunch, it says that the Access VBA special "addressof()" function doesn't necessarily work on constants because the compiler optimizes use of constants by embedding them into code. The constant might not exist as a separate variable at all.
Your problem,
@riktek, is that you are casting your expectations on someone else's language developed about 30 years ago during a time when issues of computability were considered paramount. There is nothing wrong with VBA. What is wrong is that you are blindly expecting languages to do what you want when in fact they ALWAYS do what their authors wanted. I'm trying to not be harsh here, but you are basically making faulty assumptions on what VBA will do and I can't seem to convey that to you.