Here is the code from the Load:
Private Sub Form_Load()
Dim UserName As String
Dim ComputerName As String
stat = GetUsernameComputerName(UserName, ComputerName)
MsgBox ((UserName + " " + ComputerName))
End Sub
Here is the code from the module:
Option Compare Database
Option Explicit
Public Declare Function WNetGetUser Lib "mpr.dll" Alias "WNetGetUserA" (ByVal lpName As String, ByVal lpUserName As String, lpnLength As Long) As Long 'i.e. strUserNetworkName = MMC_WNetGetUser "", strUser, 255
Public Declare Function GetComputerName Lib "kernel32.dll" Alias "GetComputerNameA" (ByVal buffer As String, ByRef nsize As Long) As Boolean
Public Function GetUsernameComputerName(strUserName As String, strHost As String)
Const MAXCHAR As Integer = 50 'Max. no. of chars. in computer name
'Dim strHost As String 'Name of computer returned by function
'Dim strUserName As String 'Network Name of User
'*****************************
'* Get User's Network Name *
'*****************************
strUserName = Space(255)
WNetGetUser "", strUserName, 255
'Debug.Print Trim(strUserName)
'******************************
'* Get User's Computer Name *
'******************************
strHost = String(MAXCHAR, 0)
GetComputerName strHost, MAXCHAR
'Debug.Print Trim(strHost)
End Function