Getting NT User Login Names from Access 2000 or 2003



I have a function called fOSUserName, that I found, to get the login name of
the person, when they open my main form.

code:
Private Declare Function apiGetUserName Lib "C:\WINNT\system32\advapi32.dll"
Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Public Function fOSUserName() As String
'returns the network login name

Dim lngLen As Long
Dim lngX As Long
Dim strUserName As String

strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen - 1)
If (lngX > 0) Then
fOSUserName = Left$(strUserName, lngLen)
Else
fOSUserName = vbNullString
End If

End Function

Problem is that it's returning mmiller followed by a bunch of square boxes.
The Left$ (in the code) and a try of Trim and a LTrim(RTrim()) is not fixing
it. When I try to assign it to a field in a log table, it always says that
my data is too big for the field.
When I assign it to a label, it shows up fine, as the boxes are not visible.

Any ideas? Thanks.

--
MichaelM
.



Relevant Pages

  • Re: ADO connections question
    ... I have a module which creates the ADO connection object to validates the ... Function dbLogin(txtUser As String, txtPword As String, txtServer As String, ... I have a specific login form that calls the dbLogin function as shown below: ... Dim strCriteria As String ...
    (microsoft.public.access.adp.sqlserver)
  • Custom login will not work
    ... When I started a new ASP project I was eager to use the login facilities ... Dim authTicket As FormsAuthenticationTicket ... Dim cookieName As String = FormsAuthentication.FormsCookieName ... PersonID = CType, Integer) ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: Login help
    ... the user login name from the system all i want is to record them using the ... Private Sub Command2_Click ... Dim strUIdCheck As Variant ... Dim strErrorMessage As String ...
    (microsoft.public.access.devtoolkits)
  • Re: Writing values to a table via VB
    ... Dim strSQL As String ... Dim UserID As String ... where UserID = fOSUserName() is ...
    (microsoft.public.access.formscoding)
  • Re: Writing values to a table via VB
    ... Dim strSQL As String ... Dim UserID As String ... where UserID = fOSUserName() is ...
    (microsoft.public.access.formscoding)

Loading