Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way for MS Access to grab the current Active Directory user?

I'm working on a spec for a piece of software for my company and as part of the auditing system I think it would be neat if there was a way to grab the current Active Directory user.

Hopefully something like:

Dim strUser as String
strUser = ActiveDirectory.User()
MsgBox "Welcome back, " & strUser
like image 613
Andrew G. Johnson Avatar asked Aug 12 '08 17:08

Andrew G. Johnson


People also ask

How do I see who is logged onto a database in Access 2016?

Press CTRL+G to open the Immediate Window. Note that the Immediate window returns a list of users who are logged onto the database.


1 Answers

Try this article - I have some code at work that will erm, work if this doesn't...

Relevant quote:

Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
                    (ByVal IpBuffer As String, nSize As Long) As Long
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" _
                    (ByVal lpBuffer As String, nSize As Long) As Long

Function ThisUserName() As String
    Dim LngBufLen As Long
    Dim strUser As String

    strUser = String$(15, " ")
    LngBufLen = 15

    If GetUserName(strUser, LngBufLen) = 1 Then
        ThisUserName = Left(strUser, LngBufLen - 1)
    Else
        ThisUserName = "Unknown"
    End If
End Function

Function ThisComputerID() As String
    Dim LngBufLen As Long
    Dim strUser As String

    strUser = String$(15, " ")
    LngBufLen = 15

    If GetComputerName(strUser, LngBufLen) = 1 Then
        ThisComputerID = Left(strUser, LngBufLen)
    Else
        ThisComputerID = 0
    End If
End Function
like image 134
JamesSugrue Avatar answered Nov 15 '22 19:11

JamesSugrue