J
Jason Lim
Dear all,
I am referring to this article:
http://www.mvps.org/access/api/api0008.htm
I thought of having a text box which displays the user's login name,
and save it to a table. So I create a text box, and bound it a field.
And the following is the code for retreving the login name. Very sorry
for my silly question, but I really know nothing about VB. errrm what
should I do with the code? Save it as a module? Let's say I name it
fOSUserName. Then, how do I call the function or the module? How to
relate it to the text box?
Thanks a lot in advance... =)
'******************** Code Start **************************
' This code was originally written by 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 **************************
I am referring to this article:
http://www.mvps.org/access/api/api0008.htm
I thought of having a text box which displays the user's login name,
and save it to a table. So I create a text box, and bound it a field.
And the following is the code for retreving the login name. Very sorry
for my silly question, but I really know nothing about VB. errrm what
should I do with the code? Save it as a module? Let's say I name it
fOSUserName. Then, how do I call the function or the module? How to
relate it to the text box?
Thanks a lot in advance... =)
'******************** Code Start **************************
' This code was originally written by 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 **************************