Cooky
Mechanical
- Jan 14, 2003
- 114
Is there a command which access the PC user name in Visual Basic?. I want to use it for the file name when generating reports created in VB
Thanks for your help.
Thanks for your help.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Sub Main()
Dim sUser As String
Dim lpBuff As String * 1024
'Get the Login User Name
GetUserName lpBuff, Len(lpBuff)
sUser = Left$(lpBuff, (InStr(1, lpBuff, vbNullChar)) - 1)
MsgBox "Login User: " & sUser
End Sub
Sub Main()
Dim sUser As String
sUser = VBA.Environ("USERNAME")
MsgBox "Login User: " & sUser
End Sub