0

I created an application in Access 2016 32 Bit, which in several update queries, log the user, by capturing it from Windows. We are now migrating to Windows 10 64 bit, and the code is not compatible. This is the code I have:

Private Declare Function apiGetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal IpBuffer As 
String, nSize As Long) As Long
Function fOSUserName() As String
'Returns the network login name'
Dim IngLen As Long, IngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
IngLen = 255
IngX = apiGetUserName(strUserName, IngLen)
If (IngX > 0) Then
    fOSUserName = Left$(strUserName, IngLen - 1)
Else
    fOSUserName = vbNullString
End If

End Function

Can someone give me a hand for a similar solution that works in 64 bit?

Thank you.

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
  • 2
    Does this answer your question? [How to get windows username in MS Access VBA on Windows Server 2008](https://stackoverflow.com/questions/34352511/how-to-get-windows-username-in-ms-access-vba-on-windows-server-2008) – Andre Jan 13 '20 at 15:21

1 Answers1

1

You need to migrate the API calls to make it compatible to 64-bit. Read Migrate Windows API-Calls in VBA to 64-bit

The correct syntax is:

Declare PtrSafe Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Also see Convert Windows API call to 64-bit in Excel VBA.

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73