Connecting Tech Pros Worldwide Help | Site Map

MS Access User Level Security with NT

Newbie
 
Join Date: Apr 2007
Posts: 4
#1: Apr 24 '07
How can I use a users NT login information to open an Access 2003 database with User Level Security?
msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,865
#2: Apr 24 '07

re: MS Access User Level Security with NT


Quote:

Originally Posted by ninjasix8

How can I use a users NT login information to open an Access 2003 database with User Level Security?

Create a table to hold the users NT login names. Then add the following declaration and function to a module. Also create a Global variable to hold the user name for further use.
Expand|Select|Wrap|Line Numbers
  1. Global uName As String
  2.  
  3. Private Declare Function GetUserName Lib "advapi32.dll" _
  4.  Alias "GetUserNameA" (ByVal lpBuffer As String, _
  5.  nSize As Long) As Long
  6.  
  7. Function getUserID() As String
  8. Dim len As Long, dlen As Long
  9. Dim str As String
  10. Dim max_String As Integer
  11. Dim username As String
  12.  
  13.     max_String = 30
  14.     cnt = 199
  15.     str = String(max_String, 1)
  16.     dlen = GetUserName(str, len)
  17.     username = Trim(Left(str, len))
  18.     username = UCase(Mid(username, 1, Len(username) - 1))
  19.     getUserID = username
  20.  
  21. End Function
  22.  
In the code behind your startup form, put the following in the forms Load event.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  
  3.    uName = getUserID
  4.    If nz(DLookup("[LoginName]","TableName","[LoginName]='" & uName & "'"), "") = "" Then
  5.       Application.Quit
  6.    End If
  7.  
  8. End Sub
  9.  
Mary
Newbie
 
Join Date: Apr 2007
Posts: 4
#3: Apr 25 '07

re: MS Access User Level Security with NT


Quote:

Originally Posted by mmccarthy

Create a table to hold the users NT login names. Then add the following declaration and function to a module. Also create a Global variable to hold the user name for further use.

Expand|Select|Wrap|Line Numbers
  1. Global uName As String
  2.  
  3. Private Declare Function GetUserName Lib "advapi32.dll" _
  4.  Alias "GetUserNameA" (ByVal lpBuffer As String, _
  5.  nSize As Long) As Long
  6.  
  7. Function getUserID() As String
  8. Dim len As Long, dlen As Long
  9. Dim str As String
  10. Dim max_String As Integer
  11. Dim username As String
  12.  
  13.     max_String = 30
  14.     cnt = 199
  15.     str = String(max_String, 1)
  16.     dlen = GetUserName(str, len)
  17.     username = Trim(Left(str, len))
  18.     username = UCase(Mid(username, 1, Len(username) - 1))
  19.     getUserID = username
  20.  
  21. End Function
  22.  
In the code behind your startup form, put the following in the forms Load event.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  
  3.    uName = getUserID
  4.    If nz(DLookup("[LoginName]","TableName","[LoginName]='" & uName & "'"), "") = "" Then
  5.       Application.Quit
  6.    End If
  7.  
  8. End Sub
  9.  
Mary

Thanks Mary!
msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,865
#4: Apr 25 '07

re: MS Access User Level Security with NT


Quote:

Originally Posted by ninjasix8

Thanks Mary!

You're welcome.
Reply