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.
-
Global uName As String
-
-
Private Declare Function GetUserName Lib "advapi32.dll" _
-
Alias "GetUserNameA" (ByVal lpBuffer As String, _
-
nSize As Long) As Long
-
-
Function getUserID() As String
-
Dim len As Long, dlen As Long
-
Dim str As String
-
Dim max_String As Integer
-
Dim username As String
-
-
max_String = 30
-
cnt = 199
-
str = String(max_String, 1)
-
dlen = GetUserName(str, len)
-
username = Trim(Left(str, len))
-
username = UCase(Mid(username, 1, Len(username) - 1))
-
getUserID = username
-
-
End Function
-
In the code behind your startup form, put the following in the forms Load event.
-
Private Sub Form_Load()
-
-
uName = getUserID
-
If nz(DLookup("[LoginName]","TableName","[LoginName]='" & uName & "'"), "") = "" Then
-
Application.Quit
-
End If
-
-
End Sub
-
Mary