Access VBA changes uppercase & lowercase randomly

依然范特西╮ 提交于 2020-08-08 03:59:53

问题


I have a coding project in MS Access. There are some developers coding and checking in the source-code to a SVN-Server. As a SVN-Server is for managing code, it recognizes changes in the source-code files. In these source-code-files there is a problem. VBA often changes uppercase and lowercase letters and we have no clue why.

When I do a commit it is i.e

'two examples
Call myfunction(txtNodeID)
rst![Username] = Environ("USERNAME")

Another developer updates his repository and uses my code and it changes to

'two examples
Call myfunction(txtNodeId)
rst![UserName] = Environ("USERNAME")

SVN recognizes this as a change. So we have many changed files although the logic did not change but Access modified uppercase and lowercase.

Does anyone know why Access is acting like this and how to prevent this?

Thank you.


回答1:


The VBA editor should enforce variable name case to be the same as the declared variable name. This means, you should be unable to write the following:

Dim someID As String
someId = "5"

It does the same with functions. So ENVIRON becomes Environ.

However, this can get weird if you don't enforce variable declaration (no Option Explicit at the top). Then the editor will have a hard time knowing which is the correct case, and tend to change everything to the first occurrence.

The solution is to get all devs to use Option Explicit, so each variable is explicitly declared and the VBA editor knows which is the correct case (and there are many additional advantages). To avoid quirks, they should also make the edited line loses focus before saving (that's when the check happens, so you can do this wrong if you really want to. If you do, it can change to the correct case when touched).




回答2:


The txtNodeID is changed to txtNodeId, because the latter is declared in the program somehow. Try this piece:

Sub TestMe()
    someVariable = 5
End Sub

Then write on another module only Public SOMEVARIABLE. The TestMe sub would look like this now:

Sub TestMe()
    SOMEVARIABLE = 5
End Sub


来源:https://stackoverflow.com/questions/50676275/access-vba-changes-uppercase-lowercase-randomly

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!