Database development and training for Birmingham and the midlands
Specialists in Microsoft Access and Visual Foxpro database training and development
I am happy to hear from existing clients but I am taking no new calls.
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
'-- Do nothing - leave the settings as they were at Design Time.
Other environment variables
Three other useful calls are:
strComputerID = Environ("ComputerName")
'-- The Windows temp folder
strTempFolder = Environ("Temp")
'-- Also the Windows temp folder
strTmpFolder = Environ("Tmp")
If you are curious, this snippet of VBA code will list the names and values available from the Windows environment:
Do Until Environ(i) = ""
i = i + 1
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.
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.