1. Create a new module named mdl_Get_User_Name
2. Paste the code below into that module and save
3. Change the control in your report footer to =GetUser()
I usually just execute this code once when the application starts, then save the value into a global variable for use throughout the program.
Option Compare Database
Option Explicit
Declare Function WNetGetUser Lib "mpr.dll" Alias "WNetGetUserA" _
(ByVal lpName As String, ByVal lpUserName As String, lpnLength As Long) As Long
Function GetUser() As String
On Error GoTo Error_trap
Dim UserN As String
Dim lpName As String
Dim NLen As Long
Dim X As Long
GetUser = "Not logged on network"
UserN = String$(255, 0)
NLen = Len(UserN)
X = WNetGetUser(lpName, UserN, NLen)
If X = 0 Then
GetUser = Left$(UserN, NLen - 1)
End If
Early_exit:
Exit Function
Error_trap:
'Display some message if desired
GoTo Early_exit
Resume Next
End Function
Code: Where the vision is often rudely introduced to reality!