handsrfull
Technical User
My database currently authenticates users using their Windows ID
I have two modules as seen below:
The first is called GetUserName
The second is called ValidateUsers
Is there a way to restrict read/write access to tables/forms based on their Windows IDs?
I have two modules as seen below:
The first is called GetUserName
Code:
Declare Function wu_GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) _
As Long
Function ap_GetUserName() As Variant
Dim strUserName As String
Dim lngLength As Long
Dim lngResult As Long
'-- Set up the buffer
strUserName = String$(255, 0)
lngLength = 255
'-- Make the call
lngResult = wu_GetUserName(strUserName, lngLength)
'-- Assign the value
ap_GetUserName = Left(strUserName, InStr(1, strUserName, Chr(0)) - 1)
End Function
The second is called ValidateUsers
Code:
Public Function ValidateUser()
'Confirm that the user should be able to enter this database
Dim db As DAO.Database, rst As DAO.Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT UserName FROM tblUSERS WHERE UserName = """ & UCase(ap_GetUserName) & """;")
'Check to see if the user name is in the list of valid users
If rst.EOF Then
MsgBox "You are not authorized to use this database!" & vbNewLine & _
"Please contact the Database Administrator for permission.", _
vbCritical, "No Authorization"
rst.Close
Set rst = Nothing
Set db = Nothing
Application.Quit
End If
rst.Close
Set rst = Nothing
Set db = Nothing
End Function
Is there a way to restrict read/write access to tables/forms based on their Windows IDs?