Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA object properties appear in lower case

Tags:

vba

ms-access

Sometimes when developing you find that typical property names show up in lower case.

TempVars.Item("abc")

Might appear like this.

TempVars.item("abc")

Or

tbxMyTextbox.Value

Shows up as

tbxMyTextbox.value

The question is why does this happen and how do you fix it?

like image 465
NWdev Avatar asked Dec 15 '22 04:12

NWdev


1 Answers

I've asked myself this question several times and seen others ask it in SO and elsewhere. In most cases the question comes up when searching for answers on other coding errors. Sometimes the developer (me too) wonders if there's something wrong that they're missing that causes this lower case issue.

A while back I ran across an answer (I'll add the original reference when I run across it again) that made the most sense and actually allowed me to correct this nagging issue.

Apparently it happens when you use a variable in lower case that has a name that's the same as a property.

So

 Dim value as string

will result in

 myObject.Value

appearing as

 myObject.value

Solution?

Because VBE apparently considers this variable across the entire IDE -- apparently without regard to scope; the way to revert to the proper case is to temporarily create the variable in upper case and avoid naming variables with the same name as existing properties in your application.

So the solution for the .value / .Value issue above would be to temporarily include the line

Dim Value as string

in a module within your app. Run the code that includes this line.

Afterwards, remove this temporary line of code.

Then as hoped, .value properties will again appear as .Value and not .value.

Of course, we should avoid those reserved words in the first place, but if at some point that wasn't done the above should fix the issue.

Here are some reserved word links:

  • Microsoft - Access 2002 & later
  • Allen Browne's bad word list
  • Reserved Word search tool (various languages)

Thanks to @ScottCraner for the nudge about avoiding reserved words.

like image 183
NWdev Avatar answered Dec 23 '22 06:12

NWdev