Forum Discussion
Access changing lettercase - redux
Here's what's going on. This is informed by my having gotten my start on Dartmouth Basic in the late 60's and realizing that the basic (pun intended) operation of tokenization hasn't changed in almost 60 years, at least in VBA.
- Your BASIC statements are compiled to a tokenized intermediate representation that is easy to interpret. This happens every time you "commit" a statement by pressing ENTER or moving the cursor away from the line. In the tokenized form, names are stored as references into a symbol table.
- There is one (and only one) symbol table (i.e. namespace) where ALL names are stored.
- A symbol table entry contains a case-sensitive spelling of every name. However, when the table is searched, the comparisons are case-insensitive.
- There can be many objects with the same (case-insensitive) name, in different scopes, but only a single entry in the table for a given name, and that entry contains the current case-sensitive canonical spelling of the name.
- When you enter a statement that "creates" a name (Dim, Sub, Function, Const, etc) the canonical spelling in the symbol table gets updated to the spelling you just typed. If you accidentally type a name that differs only in lettercase from an existing name, the symbol table gets updated with the new spelling.
So this explains how the symbol table gets updated. The next bit explains why this affects names in seemingly unrelated places.
The crucial point is that what you see in the editor is not the code that you typed
- Remember that every time you enter a statement it gets tokenized to binary opcode(s) and symbol table references. What you typed is actually discarded (except for comments).
- As soon a statement is committed and tokenized, the process is reversed and the VBA source code version of the statement is recreated. As part of that process, any names are retrieved from the symbol table.
So, committing a "name-creating" statement updates the symbol table with the current letter-case spelling of the name. This seems to trigger a global "decompile" step that updates all existing statements that refer to the changed name, which immediately affects any open code windows.
Whenever you perform any operation that involves displaying source code (open a code module, export source), the VBA source gets regenerated from the stored tokenized version, using the current letter casing from the symbol table. So changing spelling on one place affects all references to that name.
To "fix" what you perceive as broken lettercasing for a specific name, all you have to do is "commit" a "name-creating" statement with the correct letter case. It makes no difference what that statement is, even a simple Dim will work.
So, back to my example:
- I inadvertently typed Sub class_initialize(). Since this is a "name-creating" statement, the symbol table was updated to make the canonical spelling all lower-case.
- All other instances of Class_Initialize() were changed to lower-case
- To fix it, all I had to do was enter Dim Class_Initialize as Long, commit the statement, and then delete it.
Problem solved.