We help IT Professionals succeed at work.

Access 32 bit to 64 bit

We are moving to Access 2019 64 bit from Access 2016 32 bit.  I am having problems updating this code to make it 64 bit compatible.  Thanks for your help.  

Option Compare Database
Option Explicit
Private Declare Function GetComputerNameA Lib "kernel32" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Public Function GetComputerName() As String
'On Error GoTo Err_GetComputerName
Dim Username As String * 255
Call GetComputerNameA(Username, 255)
GetComputerName = Left$(Username, InStr(Username, Chr$(0)) - 1)

Exit_GetComputerName:
    Exit Function

Err_GetComputerName:
        MsgBox Err.Description
        Resume Exit_GetComputerName

End Function

Public Function GetCurrentUserName() As String
'On Error GoTo Err_GetCurrentUserName
 Dim lpBuff As String * 25
 Dim ret As Long, Username As String
   ret = GetUserName(lpBuff, 25)
   Username = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
   GetCurrentUserName = Username & ""

Exit_GetCurrentUserName:
    Exit Function

Err_GetCurrentUserName:
        MsgBox Err.Description
        Resume Exit_GetCurrentUserName
End Function
Comment
Watch Question

John TsioumprisSoftware & Systems Engineer
Distinguished Expert 2019

Commented:
John TsioumprisSoftware & Systems Engineer
Distinguished Expert 2019

Commented:
President / Owner
Fellow 2019
Most Valuable Expert 2017
Commented:
See this old thread:

https://www.experts-exchange.com/questions/27190589/GetUserName-fails-on-64bit-Access.html

 which also has some links to help with other 32 to 64 bit conversions.

Jim.
Mark EdwardsChief Technology Officer

Commented:
I'm assuming that you have Access apps created in 32-bit Access and you need to re-code them to use 64-bit Access/Office and 64-bit Windows on ALL your uses of your app.  Once you've made your code changes, you aren't going to try to get it to work on any 32-bit Access/Office machines, right?

If you are, you'll need conditional compilation to separate the 64-bit only code from the 32-bit only code.