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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you place the user login name on a Report? 2

Status
Not open for further replies.

schines

Technical User
Mar 10, 2005
18
US
I am trying to create a report that will print out the Users Login Name at the footer of the report.

Thank you for any piece of advise.

Steph
 
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!
 
Trevil

Thanks that works perfectly!!!! It was exactly what I wanted.

Thank you!
Steph
 
You could also just change the footer to
=Environ("Username")



Danny

Never Think Impossible
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top