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, 10:48
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?
 
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
 
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.
 
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?
 
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.
 
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.
 
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
 
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.
 
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
 
@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.
 
Hi. I'm having a similar issue. I have an Access database that I inherited (mdb ext). I finally got it converted to an accdb but it still states "this database was created with 32-bit..." when someone other than myself tries to open it (I uninstalled O365 64 bit and put 32 bit on my computer). I've already found that I need the PtrSafe declaration but no one is stating where. Do I need to put it at the beginning of every query? Since the error is upon opening the database I would presume not, but then where? The database does have a dashboard that is at the startup. I know how to build relationships and navigate the queries, forms, reports, etc., but that's the extent of my Access knowledge. Some insight would be helpful.
 
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
Ron de Bruin is the best! His pages taught me when I was first cutting my teeth on VBA in Excel.
He has since switched to a very Apple-focused delivery, however, and many of his earlier pages aren't available.
For a long time I used to Google the search term "ron de bruin saveas" when I forgot the constant for XLSB or XLSX
 
Nothing to do with queries, but Declarations.
 
Nothing to do with queries, but Declarations.
but where are declarations located? Everything I've researched states that I need the declaration but no one is stating where I'm supposed to be finding this.
 
Search for Declare within the whole project.
TBH I cannot see an mdb ever needing to be converted to 64bit as long as you keep using 32 bit Access.

All your colleagues appear to be using 64 bit Access. :(
Get your company to.make their mind up which they are going to use, and take it from there.
 
Ron de Bruin is the best! His pages taught me when I was first cutting my teeth on VBA in Excel.
He has since switched to a very Apple-focused delivery, however, and many of his earlier pages aren't available.
For a long time I used to Google the search term "ron de bruin saveas" when I forgot the constant for XLSB or XLSX
Unfortunately, Ron deleted all his old Excel for Windows pages with a view to making his site for Excel Mac.
Another Excel maestro is in the process of relaunching Ron's old content.

However, I contacted Dannis Wallentin who is the author of the excellent Windows API Viewer for MS Excel app. With his agreement, that tool is now hosted on my website and can be downloaded from the page below:

 
Hi. I'm having a similar issue. I have an Access database that I inherited (mdb ext). I finally got it converted to an accdb but it still states "this database was created with 32-bit..." when someone other than myself tries to open it (I uninstalled O365 64 bit and put 32 bit on my computer). I've already found that I need the PtrSafe declaration but no one is stating where. Do I need to put it at the beginning of every query? Since the error is upon opening the database I would presume not, but then where? The database does have a dashboard that is at the startup. I know how to build relationships and navigate the queries, forms, reports, etc., but that's the extent of my Access knowledge. Some insight would be helpful.
goto VBE (ctrl-g) and visit each form, report and Module code.
if you are unable to do it, someone will do it for you just upload your db.
 

Users who are viewing this thread

Back
Top Bottom