NT Login and User Table Validation

graviz

Registered User.
Local time
Today, 13:26
Joined
Aug 4, 2009
Messages
167
I have a table call "User_Auth" with two fields (Name & NT_Login). I have some code where it checks to see what a users nt login is and stores it in a variable.

Code For User Name Checking:

Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If (lngX > 0) Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = vbNullString
End If
End Function

I've always hard coded it as to which users I want to give access to (i.e. If fOSUserName = "john.smith" Then" something) . I have a project I'm working on where I would like it to loop through that table and see if it matches one of the users. I know it's probably basic but could someone please assist me with some code to get this to work?

User Name Stored in "fOSUserName"
Table Name: User_Auth
NT Field Name: NT_Login

Thanks!
 
If you just want to check it exists in the table you don't need to loop through it can't you just use a DLookup?

Unless I've not understood what you need to do.
 
If you just want to check it exists in the table you don't need to loop through it can't you just use a DLookup?

Unless I've not understood what you need to do.

So how would you write it?

Dim UN_Check as String

UN_Check = DLookup("[NT_Login]", "User_Auth", fOSUserName")

I know the last part of a dlookup is the criteria so how would I write it? I haven't used a dlookup before.
 
If IsNull(DLookup("[NT_Login]", "User_Auth", "[NT_Login] = '" & fOSUserName & "'")) Then

'Code here if it doesn't exist

Else

'Code here if it does

End If
 
If IsNull(DLookup("[NT_Login]", "User_Auth", "[NT_Login] = '" & fOSUserName & "'")) Then

'Code here if it doesn't exist

Else

'Code here if it does

End If

Thanks! I knew I was making it more complex than it needs to be.
 

Users who are viewing this thread

Back
Top Bottom