User Name Stamp

  • Thread starter Thread starter Dan
  • Start date Start date
D

Dan

Hi:

Anyone knos how do you make/incorporate this code into a
form...I was
trying and is not working! what am I missing

Thanks,

Dan
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

..
 
Well, you really wouldn't put that in a form. You'd make it a public
function that you could call from any form. (That's how I did it anyway)
Save it in a module as a Public function.

Then in your forms you can use the fosUserName and insert the windows login.

Rick B




Hi:

Anyone knos how do you make/incorporate this code into a
form...I was
trying and is not working! what am I missing

Thanks,

Dan
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

..
 
Hi Rick:

Thanks!; but is not working.. I do not know why...

Do I have to call it from the field that is suposed to
store the login ID?

Thanks,

DAn
 
What are you trying to accomplish?

I created a public function in a module. My module is named "GetUserName".
Note that your module name and your function name cannot be the same.

I have a form with an unbound text box on it. in that text box I have...

=fOSUserName()


When I open the form, that text box displays the network logon.

Hope that helps. If not, tell us what you are trying to do. You ask where
to put the function, but you never explain the results you are trying to
obtain.

Rick b


Hi Rick:

Thanks!; but is not working.. I do not know why...

Do I have to call it from the field that is suposed to
store the login ID?

Thanks,

DAn
 
Back
Top