Microsoft Visual Basic for Applications Compile error: The code in this project must be updated for use on 64-bit systems. (1 Viewer)

Dippies

New member
Local time
Today, 13:34
Joined
May 21, 2020
Messages
14
Good day all,

Microsoft Visual Basic for Applications

Compile error:

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 the PtrSafe attribute.

I have been running MS Office Professional 2010 on Windows 7 Professional
I copied my MSAccess program onto a new laptop 64bit (Windows 11 Home Single Language) edition.

Please help, How do I correct the above error?
 

adhoustonj

Member
Local time
Today, 07:34
Joined
Sep 23, 2022
Messages
150
It sounds like you need to add a 64 bit declaration. Below is an example.

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

32 or 64 bit:
Code:
#If VBA7 And Win64 Then
Private Declare PtrSafe Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
#Else
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
#End If
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 06:34
Joined
Feb 28, 2001
Messages
27,186
Search this form for "converting to 64-bit Access" to find several articles on the steps involved. Most of the problems will be in your modules. Most are related to protecting against various function/sub calls that would now use 64-bit addresses. If you have any API calls in your code, they will all need attention, but if you have functions and subs that pass object variables, they will also require assistance.

OR remove 64-bit Office from the new machine and install 32-bit Office (to include Access).

To head off one of the obvious questions often asked by new members, you CAN run 32-bit apps on a 64-bit machine. (I'm doing that right now.) The only reason you would need 64-bit Office is if you needed to do a million-row Excel spreadsheet or a 10,000 page Word document. If you have no need for huge documents, you can very comfortably live under a 32-bit version of Office.

Part of the problem is that until (relatively) recently, the default Office install was for the 32-bit "flavor" - but now the default on a 64-bit machine is the 64-bit version of Office. Your Win11 will almost certainly have used the 64-bit default.
 

Gasman

Enthusiastic Amateur
Local time
Today, 12:34
Joined
Sep 21, 2011
Messages
14,305
It sounds like you need to add a 64 bit declaration. Below is an example.

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

32 or 64 bit:
Code:
#If VBA7 And Win64 Then
Private Declare PtrSafe Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
#Else
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
#End If
Never going to happen to me, but how are you meant to know when something should be LongPtr in the 64bit version?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:34
Joined
Oct 29, 2018
Messages
21,473
Please help, How do I correct the above error?
Depending on which APIs you're using, I would consider using VBA replacement codes, so you don't have to worry about fixing them for 64 bit Access.
 

GaP42

Active member
Local time
Today, 21:34
Joined
Apr 27, 2020
Messages
338
I found the free apps from Peter Cole very useful for identifying and providing the changes needed - as a first pass
Access 32to64 Bit (thememydatabase.co.uk)

And then some further actions - and advice received.
 

isladogs

MVP / VIP
Local time
Today, 12:34
Joined
Jan 14, 2017
Messages
18,225
As well as Peter Cole's tool, there is also an extensive text file from MS
I also use the excellent Windows API Viewer for MS Excel. It used to be on Excel Automation - Ron de Bruin but I can't find the exact page currently
 

Dippies

New member
Local time
Today, 13:34
Joined
May 21, 2020
Messages
14
It sounds like you need to add a 64 bit declaration. Below is an example.

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

32 or 64 bit:
Code:
#If VBA7 And Win64 Then
Private Declare PtrSafe Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
#Else
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
#End If
Thank you, I added the PtrSafe "verb" to the Declare statement and it is working.
Much appreciated.
 

isladogs

MVP / VIP
Local time
Today, 12:34
Joined
Jan 14, 2017
Messages
18,225
You've only done the first step.
Adding PtrSafe will allow the project to compile and therefore it will run.
However that isn't usually all that you need tondo to get APIs and Type declarations working correctly.
For example all handles/pointers such as hWnd need to be converted from Long to LongPtr
 

AHeyne

Registered User.
Local time
Today, 13:34
Joined
Jan 27, 2006
Messages
92
@Dippies : Maybe you can show us the API(s) where you added PtrSafe? That would make it more clear, if you will have to do some more to really let it run stable.
 

Users who are viewing this thread

Top Bottom