I have a test form that is called 'Form1'. On this form I have a textbox
called 'text0'. What I want to happen is show the ID of the person who is
signed onto the computer when 'some event' occurs. I was trying initially to
have it show on MouseMove then changed it to AfterUpdate. Neither has
worked.
On the form in the event procedure for 'on enter' I have the following code.
Private Sub Text0_Enter()
Call fOSUserName
Text0 = strUserName
End Sub
In the module named 'apiGetUserNameA', I cut and pasted the following code
'******************** 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 **************************
Where am I going wrong? Please be detailed as possible as I am trying to
learn VB code on the fly from a book.
Thanks