Reading the Windows username
It's really useful to be know who is logged into your Access database
but sometimes you don't want the overhead of forcing your users through
a login and password at startup. The answer is to retrieve the user's
Windows identity and Access makes this very easy for us with the VBA function
Environ().
Environ() in fact allows us to retrieve a
variety of settings from the Windows environment but the most useful of
these is the username:
strUserID = Environ("UserName")
If strUserID = "franklin" then
Me.AllowDeletions = True
Me.AllowAdditions = True
Else
Endif
Other environment variables
Three other useful calls are:
strComputerID = Environ("ComputerName")
strTempFolder = Environ("Temp")
strTmpFolder = Environ("Tmp")
If you are curious, this snippet of VBA code will list the names and values available
from the Windows environment:
i = 1
Do Until Environ(i) = ""
Debug.Print Environ(i)
i = i + 1
Loop
Most of these values are too obscure to be useful but if you ever need to know whether
your user has a two-core or four-core core processor then the
Environ() function can tell you.
Security Warning
It is possible that a knowledgeable user might be able to falsify the user name in
the environment variables. There is a more robust alternative technique using API calls
described on
Allen Browne's
Access site.
|