David W. Fenton said:
Is there some circumstance where DBEngine.Workspaces(0).UserName and
CurrentUser() will return different results? I've never used
DBEngine.Workspaces(0).UserName to get the Jet username, so don't
know why you'd be doing it at all.
Well ... there is a difference, albeit a small one.
Here's my test code ...
Public Sub TestUserNames()
Debug.Print CurrentUser()
Debug.Print DBEngine.Workspaces(0).UserName
End Sub
.... and here's the result in the Immediate window ...
testusernames
Admin
admin
The difference being that DBEngine.Workspaces(0).UserName does not
capitalize the initial letter. So the following code ...
Public Sub TestUserNames()
Debug.Print StrComp(CurrentUser(), "admin", _
vbBinaryCompare)
Debug.Print StrComp(DBEngine.Workspaces(0).UserName, "admin", _
vbBinaryCompare)
Debug.Print
Debug.Print StrComp(CurrentUser(), "Admin", _
vbBinaryCompare)
Debug.Print StrComp(DBEngine.Workspaces(0).UserName, "Admin", _
vbBinaryCompare)
End Sub
.... returns these results ...
testusernames
-1
0
0
1
This is of course an artificially contrived example.
Maybe the code was originally written by someone more familiar with VB than
Access. Or someone who thought they might want to port the code to VB
someday.
Anyway, while it probably would be safe to change the code to use
CurrentUser instead of DBEngine.Workspaces(0).UserName (unless there is code
doing something like my example above, which seems unlikely) might that not
be a case of treating the symptom rather than the underlying cause? As far
as I know, DBEngine.Workspaces(0).UserName should work, so if it isn't
working, something is wrong that probably needs to be fixed - mostly likely
either a references problem or code corruption, as others have suggested.