Rename the text box to something else (e.g. txtOSUserName).
--
Terry Kreft
MVP Microsoft Access
"Stuart Masters" <stuart.masters@pcs-tr.swest.nhs.uk> wrote in message
news:40878b40$0$206$75868355@news.frii.net...[color=blue]
> Many thanks for the links you provided me with. However, I am having a
> few problems. I hope you can help.
>
> I have created a new text box called fOSUserName and then in code
> created a new module. In this module I placed the code:
>
> ' 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
>
> This code is not bringing up the current username and just leaves #Name?
> in the text box. Could you please tell me where I'm going wrong.
>
> Many thanks
>
> Stu
>
>
>
> *** Sent via Developersdex
http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it![/color]