none
Problem calling fOSUserName function RRS feed

  • Question

  • A user is getting the below message.

    I've never seen this message before. What does it mean and how do I fix it?

    I have code in almost all my applications that reads the current user's network id.

    I've used it for years and never had a problem before.

    Tuesday, August 20, 2019 2:33 PM

All replies

  • This is a problem with a Windows API function call presumably used by your fOSUserName function. It means that the windows API function GetUserNameA cannot be located in the advapi32 DLL.

    It could be that the file advapi32.dll is missing, corrupted, for some reason not registered on your user's PC or maybe an issue with 64bit version of Access.


    Jon Lewis

    Tuesday, August 20, 2019 3:31 PM
  • Post your Declarations and your function. Maybe we can spot something.

    One thing...this is a 32-bit DLL. You're not using the 64-bit Windows, are you?


    Bill Mosca
    www.thatlldoit.com
    http://tech.groups.yahoo.com/group/MS_Access_Professionals

    Tuesday, August 20, 2019 5:48 PM
  • This is part of a common front-end that each user has a copy of.

    The code has been in use by multiple users for many years.

    This is the only user having this issue.

    It's possible this user might have a different operating system. I'll have to check.

    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
       On Error GoTo ER
       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
       Exit Function
    ER:
       MsgBox Err.Description, , "fOSUserName"
       fOSUserName = vbNullString
    End Function

    Tuesday, August 20, 2019 6:44 PM