I ran into the same issue building my database. What I ended up doing is writing a procedure that gets the username of the person currently logged into the computer, and based on that return, it compares the returned name to the name previously placed in a table along with a "security level" (1-4) 4 being the super user and 1 being general user. And then I enable or disable functions based on what level returns.
I thought about the password, but I figure if the user has to log into the computer through a network, there's no reason to make them log into the database as well. My database requires some sort of security, but the network takes care of that for me already.
Specifically place this code in your home forms open event:
Private Sub Form_Open(Cancel As Integer)
Dim varResponse As Variant
varResponse = MsgBox("You are currently logged into this computer as: " & " " & ReturnUserName & vbCrLf & vbCrLf & "If this is incorrect, please press cancel, logout the current" _
& vbCrLf & "user and login with your credentials" & vbCrLf, vbOKCancel)
If varResponse = vbOK Then
ElseIf varResponse = vbCancel Then
And place this code in a module:
Public Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Function ReturnUserName()
Dim strUser As String, X As Integer
strUser = Space$(256)
X = GetUserName(strUser, 256)
strUser = RTrim(strUser)
ReturnUserName = Left(strUser, Len(strUser) - 1)
I pulled that information from somewhere on the internets..not sure where though.
Were your computer set up on a network that required the users to log in to Windows, that message would return the username of the person currently logged into the computer. I.E.
"You are currently logged in as cdoopyschmitt" A table, which I called users has a column for the username of the people who are going to be logging into the computer to use the database and a column for userlevel which will be 1 through 4. 4 being the highest authorization. You can then enable or disable certain functions of your database depending on what level the person is.
Is it super secure? No. But it works for my needs because of the nature of the people I work with.
By placing the code in a module I mean goto create and all of the way to the right you'll see Module, Class Module and Macro (or something). Click Module, copy and paste the code and save it as something, the name doesn't really matter.
The first code simply pops a message up and reminds the user who's logged in, and if it's not them, log out of windows and log back in under their stuff. It uses the function ReturnUserName to get the username of the person logged in.
The reason your screenshot doesn't include the name is because you haven't added the 2nd code (the function ReturnUserName) into a module...so essentially the first code is calling a function that doesn't exist yet.