Chapter 40 Set Up Levels of User Security
Chapter 40 Set Up Levels of User Security
B
ecause your application is likely to be multiuser, you will need some kind of
security over who can do what in your database and what they are allowed to see.
You may have users who can only see very basic information, users who can see more but
cannot change records, users who can change records, and administrators who can create new
users and change privileges.
You can use VBA to do all of this, but you first need to set up a table of users. Click
Create on the Access menu and then click the Table Design icon in the Tables group of the
ribbon. Create two text fields:UserNameandUserLevel. Save the table astblUserRights.
Populate the table with the user name of each user (their Windows login ID) and their user
level. The levels can be administrator, expert, novice, and basic.
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 API call will allow you to get the user name (as discussed in Chapter 23).
You also need to add in a public function to get the user level:
Public Function ReturnUserLevel()
Dim strUser As String, X As Integer, RecSet as Recordset
strUser = Space$( 256 )
355