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

Capture User Name to print on report 3

Status
Not open for further replies.

quig699

Technical User
Nov 7, 2006
42
US
Hi, I am looking for a simple way to capture the user name of the person who is printing a report. I am just looking to have their name print on the footer. I am not looking to have it stored anywere. I am able to capture the user name when people enter data, but everything I try to capture it for the report has failed. Any suggestions??

Thanks,

Amy
 
What user name are you talking about? Access security? Windows log-on? What code are you using on the form that does not work on the report?
 
the workgroup username is stored in a global accessible variable called currentuser...

if you want to the the system username, then you'll have to use api functions, there's plenty of examples you can google for that...

--------------------
Procrastinate Now!
 
I was looking to get their windows login. Thanks for your help!!

Amy
 
You didn't state whether you needed code for the windows login. In case you do, check out
Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Hi Duane,

I am looking to get the windows login. I actually found the link you suggested but I did not work. What should I name the module and what do I put in the text box where the windows login would appear?

Thanks

Amy
 
Make sure the name of your module is not the name of your function. That's another good reason for consistently using a naming convention. All my modules are named beginning with "bas". Other developers might use "mod..."

"did not work" isn't very descriptive. Can you be more specific?

To display the user name in a text box, set the control source to:
=fOSUserName()

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Amy,

Input this code into the module you create:

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

'-----------------------------------------------------------------------------------------
' This code is used to retrieve the network user name by accessing the API apiGetUserName.
' Created by: Unknown (Found on Dev Ashish web site ' This code has not been altered in anyway.
' Added to database: 27 dec 1999
' Added by: Richard Rensel
'-----------------------------------------------------------------------------------------

Function fOSUserName() As String
On Error GoTo fOSUserName_Err

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 = ""
End If


fOSUserName_Exit:
Exit Function

fOSUserName_Err:
MsgBox Error$
Resume fOSUserName_Exit
End Function

This will work!

Also create a text box on the footer and in the control source Paste this:

=FOSUserName()

Presto you are done!

This will work.
 
Thanks to everyone for all of their help!!! I got it to work!!

Amy
 
Quick question on this subject.

Whats wrong with putting a textbox in the footer and entering

=Environ$("Username")

as this will also populate the field with the windows login and requires a lot less coding.

Just curious really.

If you make something idiot proof - They'll Only make a better idiot!!!
 
Thanks, must of been lucky so far, but will bear this in mind in the future.

If you make something idiot proof - They'll Only make a better idiot!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top