Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms / October 2005

Tip: Looking for answers? Try searching our database.

Using the Windows Username in an Access DB

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
fred@besttechsolution.com - 15 Oct 2005 19:56 GMT
I've read a few posts that explain how to capture the windows username,
but I'm having trouble getting this into a form.

I've added the following code to a public module:

Option Compare Database

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

When I try to user GetUserNameA or fOSUserName, I get a response of
#NAME.

Am I calling the code incorrectly?

Thanks,

Fred
Douglas J. Steele - 15 Oct 2005 21:38 GMT
What did you name the module? If you called it fOSUserName, rename it:
modules cannot be named the same as functions or subs.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> I've read a few posts that explain how to capture the windows username,
> but I'm having trouble getting this into a form.
[quoted text clipped - 38 lines]
>
> Fred
fred@besttechsolution.com - 18 Oct 2005 22:51 GMT
Thanks Doug.  

Renaming the module fixed the problem.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.