Full Version: Capture logged on user name & or PC name
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
rpacecar
I have an accde and was curious if it is possible to have the Submit onclick procedure capture the logged on user of the PC who is running the form and/or the pc name, and insert them into a table field.

ANyone know how I can accomplish this?

to dive in deeper..

How can I validate the logged on user to allow or deny the submission?

Thanks for any direction on this.
Bob G
do you have a table with authorized usernames ??
rpacecar
no.. but that will not be difficult to accomplish.. I only have 10 users
Bob G
There are a few ways you can go depending on how much you want to do. You can create a login screen where they enter their name, you compare it to this new table and if they are in it they get your main form. Then you can also have in that table an access level number. If the number is say 5 then they are run reports only. if it is a 10 then they can open forms. If you don't want to do it that way, look at this link.

http://www.databasedev.co.UK/get_username_...mputername.html
datAdrenaline
A simple way to get the current user is with this VBA command ...

Environ("UserName")

----

But most consider the following api call's and VBA User Defined Functions to be the preferred methods ...

CODE
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Private Declare Function apiGetComputerName Lib "kernel32" Alias _
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Public Function GetComputerName() As String
'Returns the computername

    Dim lngLen As Long, lngX As Long
    Dim strCompName As String

    lngLen = 16
    strCompName = String$(lngLen, 0)
    lngX = apiGetComputerName(strCompName, lngLen)

    If lngX <> 0 Then
        GetComputerName = Left$(strCompName, lngLen)
    Else
        GetComputerName = ""
        MsgBox "", vbYesNo
    End If

End Function

Public Function GetUserName() 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
        GetUserName = Left$(strUserName, lngLen - 1)
    Else
        GetUserName = ""
    End If

End Function


Edits:
Sorry for dup info dazed.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.