We help IT Professionals succeed at work.

Compile error

SteveL13
SteveL13 asked
on
I'm getting the following error after upgrading to a new computer:

"The code in this project must be updated for use on 64-bit systems.  Please review and update Declare statements and then mark them with PtrSafe attribute."

This is the code that is failing:

Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

How do I fix this?
Comment
Watch Question

President / Owner CARDA Consultants Inc.
Distinguished Expert 2018
Commented:
The MS version is
Declare PtrSafe Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Open in new window


But with your name it would be
Declare PtrSafe Function apiGetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Open in new window

Most Valuable Expert 2014
Commented:
"I'm getting the following error after upgrading to a new computer:"

What you have advertently--or inadvertently -- done is install 64-bit, and not 32-bit, MS Office.
Your existing database was coded for 32-bit Office -- and so, you are getting

"The code in this project must be updated for use on 64-bit systems.  Please review and update Declare statements and then mark them with PtrSafe attribute."

Unless you need the capabilities that 64-bit MS Excel has, your simplest short-term solution may be to uninstall 64-bit Office and install 32-bit Office (Office, not Windows -- damn near all Windows installation have been 64-bit for years.)
Your long-term solution is to research what changes from 32-bit VBA to 64-bit VBA, update all your code and move EVERY user to 64-bit Office.
Most of the change is the PtrSafe Declaration, but not all.

Have a gander
https://docs.microsoft.com/en-us/office/client-developer/shared/compatibility-between-the-32-bit-and-64-bit-versions-of-office

Nick67