AllExperts > Using MS Access 
Search      
Using MS Access
Volunteer
Answers to thousands of questions
 Home · More Using MS Access Questions · Answer Library  · Encyclopedia ·
More Using MS Access Answers
Question Library

Ask a question about Using MS Access
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Bob Heifler
Expertise
ALL MICROSOFT ACCESS DESIGN AND PROGRAMMING QUESTIONS - Free Access Tutorial Videos are available to you at my web site. Fifteen years of Microsoft Access experience allows me to answer most of your questions. Common question example files available here.

Experience
Microsoft Access programming since 1994

Publications
Web Article published - See Microsoft Access Tips & Best Practices are available to you at my web site. Web Site Page of 'Microsoft Access Tips & Best Practices'

Education/Credentials
UCLA GRAD, Member of Association of Database Developers

Past/Present Clients
Bob Heifler's Clients


 
   

You are here:  Experts > Computing/Technology > Business Software > Using MS Access > Display user name

Using MS Access - Display user name


Expert: Bob Heifler - 7/8/2008

Question
Is there a way to add a button that by clicking on it will display the user name in a given field?  I've had good luck with it in Excel with =Environ("username"), but can't quite get it work in Access.

Answer
Wes,
I have used the following code from this programmer:

---Posted by Dev Ashish---

------------------------------------------
API: Network User Name
------------------------------------------

(Q) How do I retrieve the UserName with which the user is logged into the network?

(A) Paste the following code in a new module and call the function fOSUserName.


'******************** Code Start **************************
'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 = ""
   End If
End Function
'******************** Code End **************************

Ask a Question


 
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.