Here's an API call will do it:
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long
Private Sub Form_DblClick()
Dim sUserName As String
Dim lSize As Long
lSize = 20
sUserName = Space(20)
Call GetUserName(sUserName, lSize)
'trim off the trailing spaces
sUserName = Trim(sUserName)
'trim off the trailing null
sUserName = Left(sUserName, Len(sUserName) - 1)
MsgBox sUserName
End Sub
the sUserName must be initialized before sending it into the function. lSize, on
the way in indicates the length of the buffer, but on the way out, indicates the
actual length of the string returned. sUserName's value is NULL terminated, so
after removing the trainling blanks, then remove the trailing NULL value.
hope this helps,
john