Network logon ID and Access

  • Thread starter Thread starter Boetie
  • Start date Start date
B

Boetie

Guest
I am currently developing a benefit logging system for the guys at work.
On entry into the system the user must login using his/her windows NT logon ID. This ID are the same as an ID in my DB's user table with a password in the table against their respective ID, in the user table are a auto number ID field which I use as a lookup number in other tables.

With the attached code I am able to pick up the user network ID and I am trying to look it up in the user table in order to pick up the auto number ID that is the value being remembered in the "Select User Logon Name, please :" dropdown box.
I want to use this value to set the default value in the drop down box and in other forms, but I keep on getting the following message as per screen dump.

I suspect that the string type is different because the value I am looking for is in the table under the right field. Can someone please help me.

Thanks

P.S. The code I am using is :

Function fOSUserName() As String
On Error GoTo fSOUserName_Err

Dim IngLen As Long
Dim IngX As Long
Dim strUserName As String
Dim strUserName1 As String

strUserName = String(254, 0)
IngLen = 255
IngX = apiGetUserName(strUserName, IngLen)

If IngX <> 0 Then
'StrConv(string, conversion, LCID)


strUserName = StrConv((Trim(Left(strUserName, IngLen - 1))), vbLowerCase)
strUserID = DLookup("[User_Detail_ID]", "Ltbl_User_Detail", _
"[User_Login_Name]= " & strUserName)
fOSUserName = strUserID

Else
fOSUserName = 0
End If

fSOUserName_Exit:
Exit Function

fSOUserName_Err:
MsgBox Error$
Resume fSOUserName_Exit

End Function
 

Attachments

  • Error msg.JPG
    Error msg.JPG
    95 KB · Views: 192
and I am trying to look it up in the user table in order to pick up the auto number ID that is the value being remembered in the "Select User Logon Name, please :" dropdown box.

How are you doing this?

Peter
 
If you are using Access2002 you can ditch that code and use the Environ("username") function.

You combo's bound field is most likely the autonumber. You should use a lokup to get this number and set the combo to that.
 
Good advice, it also works in Access 2007:
Here is a short loop to get the other values with some key fields:
Sub EnvironOptionsList()
' View a list of the program environment variables
Dim X As Integer
For X = 1 To 39
Debug.Print "Environ " & X & " is " & Environ(X)
Next X
' Most useful
'Environ 5 Is COMPUTERNAME = DEND420
'Environ 34 Is USERDOMAIN = VirtualWorld
'Environ 35 Is UserName = Rx_
End Sub
 
Good advice,

Well, SEMI-Good Advice. Environ may work just fine but if a user knows that you can set it simply in a code window or something they can become another user. So, if I typed in the immediate window, or used a command window, I could use:

Environ("username") = "bud"

then I just became bud instead of bob and can go do things as if I was bud.

Best to use the fOSUserName code with the API as that is safer.

Just an FYI.
 
I too use Environ("UserName")

First I get the UserName and then go to the Employees Table:
Code:
Function GetWinUserName()
    GetWinUserName = VBA.Environ("UserName")
End Function

Then

Code:
Function GetUser()
Dim db As DAO.Database
Dim rs As DAO.Recordset
    With CodeContextObject
        Set db = CurrentDb
        Set rs = db.OpenRecordset("SELECT EmployeesLookup.Employee, EmployeesLookup.[Employee Login], EmployeesLookup.[Employee Inv Approval] FROM EmployeesLookup WHERE EmployeesLookup.[Employee Login] = '" & GetWinUserName & "'")
        Do
            .UserDB = rs!Employee
            .UserInv = rs![Employee Inv Approval]
            rs.MoveNext
        Loop Until rs.EOF
    
        rs.Close
        Set rs = Nothing
        Set db = Nothing
    End With
End Function

This Employees Initials are then placed on the Main Menu and referred to through the database.

Simon
 
I don't think you should have a list of logins at all - not viewable by the user.

Just have it come up and ask for a password. Use either the fOSUserName function you have or Environ("UserName") to get the current logged on user and then when they put a password in and hit okay, compare that password to the one in the row with their user name and see if it matches.

I use a similar login, but no passwords. I get the username of the person opening the database. If they are not in the list of allowed users, the database will close. If they are, it checks their access level and shows only menus with functions they are authorized to run.

You can do this depending on how securely your systems are setup on your network. If you don't allow the creation of local user accounts at all, you force the person to log into the computer using network authentication - they can't just create a new local account. And if they did the DB shouldn't work anyway as you shouldn't have access to the network share where the back end is anyway. But if done right there is no real need for a password. Users should lock their workstations when they are not present.
 

Users who are viewing this thread

Back
Top Bottom