CHAPTER
23
Getting the Login ID
A
ccess applications are multiuser and you can have several users loading your
application at once. If your application is deployed to a server in your organization
and has no protection on it, then anyone who comes across the file can load it up
and start using it. This would pose huge problems in the areas of data security and confidentiality.
You can protect your database by saving it with a password so that every user must know
the password, but the problem here is that people may circulate the password to unauthorized
users, and you would have absolutely no check as to who is using the application and what
they are doing.
Users may also find it irritating to input a password when they have already logged on to
their PC, and the system already knows who they are.
Using a simple API call (see Chapter 20 for more details on API calls), you can find out
the identity of each user as they load up your application.
Create a new module by clicking Insert | Module on the VBE menu. Enter the following
declaration into the General area at the top of the module:
Public Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
This sets up a link to the function GetUserName in the dynamic link library advapi32
(which is supplied as part of the Windows operating system).
279