Hello,
A user is getting a compile error that the code needs to be updated for use on a 64-bit system after getting a new computer. I don't know anything about this and am just trying to help out, but I appear to have a 64-bit system and don't get any errors. I am not well versed in coding but I tried to update after Googling, but it still doesn't work. It now gives a compile error: ByRef argument type mismatch. Can someone please tell me what needs to be updated in this code? And will changing this make it not work for other people who are not having an issue? Thank you!
A user is getting a compile error that the code needs to be updated for use on a 64-bit system after getting a new computer. I don't know anything about this and am just trying to help out, but I appear to have a 64-bit system and don't get any errors. I am not well versed in coding but I tried to update after Googling, but it still doesn't work. It now gives a compile error: ByRef argument type mismatch. Can someone please tell me what needs to be updated in this code? And will changing this make it not work for other people who are not having an issue? Thank you!
Code:
Option Compare Database
Private Declare PtrSafe Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As LongPtr) As Long
Function fOSUserName() As String
' Returns the network login name
Dim lngLen As LongPtr, 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