Using the API call for the current username

P

Peter

Hi again...i have an issue with "picking up" the username of the Windows
system.

http://www.mvps.org/access/api/api0008.htm. I copied the whole code and i
pasted it in a module (Module1) this is how it looks:

Option Compare Database

' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
______________________________________________________________
Function fOSUserName() As String
' Returns the network login name
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

I followed the conversation Subject: Re: Returning current user from SQLServer

And the bottom line is, this is what i need. I want the username to be
posted on my opening form (whiwch is always open when the application runs)
in order to refer to it later. I have created a textbox, "Username". On the
opening event of my form i use DoCmd.Maximize...were do i put Me.txtUserName
= fOSUserName????

I appologize for my ignorance :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Update username 8
Update form field 2
Porting from 2003 to 2007 6
Capitalise 6
Retrieving and setting user logon name in a form 2
Function Parameters 1
Get domain username 2
Another audit Trail module 8

Top