Help on Retrieving Security Infor through VBA Code

usermj

Registered User.
Local time
Today, 14:03
Joined
Dec 12, 2004
Messages
39
I've used 'Tools->Security->User and Group Account' wizard to create several users for access my MS-database.

Is there any chance that I can retrieve those information (logging username etc) through VBA code?

I try to use those security information to create a logging file (maybe saved into a table)which can record all the operations done by every user. So the logging username will be vital information for me to obtain at this stage.

BTW, is there any chance we can integrate the Windows logging username with the MS-Access one. So when users logged into the windows and open the MS-Access database, system can automatically retrieve the logging usename from windows itself rather than asking for any user name and password again.

Many Thanks

Mengjie
 
Search for the posts related to the Environ() function. The CurrentUser() function will give you the users login name. Add my user name to the search for samples and examples I have posted.
 
Thanks :D

I found some relevant previous posts. I gonna have a look.

Many thanks
 
I use the following in Excel to identify users. It should work in Access to, may need a little tweaking. It returns the Windows Login Name (I presume you are on a LAN at work) rather than anything entered by the user in Office Applications.

Code:
' Function to find the windows longin username, not the one you can set in excel
Declare Function apiGetUserName Lib "advapi32.dll" Alias _
                 "GetUserNameA" (ByVal lpBuffer As String, _
                 nSize As Long) As Long

Function GetUserName() As String

    Application.Volatile
    Dim sBuff As String * 25
    Dim lBuffLen As Long
    
    lBuffLen = 25
    apiGetUserName sBuff, lBuffLen
    GetUserName = Left(sBuff, lBuffLen - 1)
    
End Function

Sub ShowUserName()
    MsgBox GetUserName
End Sub
 
Less work, tastes great!

Code:
 MsgBox "Network Name: " & Environ("UserName")
 MsgBox "Computer Name: " & Environ("ComputerName")
There are more available, search for Environ.
 

Users who are viewing this thread

Back
Top Bottom