display login name

qwertyjjj

Registered User.
Local time
Today, 10:57
Joined
Aug 8, 2006
Messages
262
I need to display the users' WIndows login name on a report in Access.
Is there a way to do this through VBA.
I have a label box setup for which I would do something like lbl_Name.Caption = variable
 
Public Function GetWinUserName()
GetWinUserName = Environ("UserName")
End Function

Put that in a module (either 'fn_GetWinUserName' or in a library of routines)

Then, in your report's OnOpen event, put this:

lbl_Name.Caption = GetWinUserName
 
And, if you want to see the rest of the Environ variables available:

Code:
Sub EnvironList()
    ' Warning:  Never refer to an Environ value by its 'number', as you
    ' will get unpredictable results.  Always include the Environ Name
    ' as in the GetWinUserName function.
    Dim i As Integer
    Dim stEnviron As String
    For i = 1 To 50                   ' get the environment variable
        stEnviron = Environ(i)        ' see if there is a variable set
        If Len(stEnviron) > 0 Then
            Debug.Print i, Environ(i)
        Else
            Exit For
        End If
    Next
 End Sub

Edited: added comments commented the first Dim line...
 
Last edited:

Users who are viewing this thread

Back
Top Bottom