Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grabing user name when logging in

Status
Not open for further replies.

Brianfree

Programmer
Feb 6, 2008
220
GB
Hi, i am using access' own security for the database, is it possible to user the username as a global variable such as when modifying a record i can record the date/time and who modified it?

regardsm

Brian
 
Have a look at the CurentUser property.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
When Access security log-in is used, CurrentUser will return the user name.
 
I have tried using access security but it adds security to all of my databases not just this one. Is there a way round this?

Many thanks.
 
This has been around for quite a while, and I use it in a lot of my applications.(I got it off the web somewhere).It simply makes an API call to get the user name.

Usage:

myvar = fOSUserName

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

Function fOSUserName() As String
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



Tyrone Lumley
SoCalAccessPro
 
I have tried using access security but it adds security to all of my databases not just this one. Is there a way round this?

You may wish to read the FAQ on security which shows how to set up various security files:

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top