Fix Access VBA Code After Moving to 64-Bit Office
Question details
Determine why Access VBA code fails on a new computer and make it compatible with the installed Office edition.

- Product
- Microsoft Access
- Device & OS
- 64-bit Windows
- Scenario
- Access VBA code that compiled on one computer is opened on another computer with a potentially different Office bitness.
- Observed behavior
- The code fails to compile on the new computer even though both computers run 64-bit Windows.
On both computers, open Access and select File > Account > About Access to compare the installed 32-bit or 64-bit editions. Note that 64-bit Windows can run either edition of Office.
Update VBA Windows API declarations for 64-bit Access
Use this approach when the code calls Windows APIs and needs to work in 64-bit Access.
In VBA7, Windows API Declare statements need PtrSafe, and pointer or handle values generally need LongPtr. Do not replace every Long with LongPtr: ordinary 32-bit numeric values may still require Long.
Use conditional compilation if the database must also support older versions of VBA. Review related structures, callbacks, and variables as well as the declarations.
Open the database in Access and press Alt+F11. Select Debug > Compile to identify the first declaration or line that fails.
In the VBA editor, select Edit > Find and search the current project for Declare statements. Check each function's Windows API documentation for its parameter and return types.
Add PtrSafe to VBA7 Declare statements and use LongPtr for parameters and return values that represent pointers or handles. For example, a GetActiveWindow declaration can use: Private Declare PtrSafe Function GetActiveWindow Lib "user32" () As LongPtr.
For older VBA versions, place the VBA7 declaration under #If VBA7 Then and a legacy declaration under #Else, ending with #End If. For the GetActiveWindow example, the legacy declaration returns Long and omits PtrSafe.
Select Debug > Compile again, resolve any remaining errors, and run the affected database features on each Access edition you need to support.

Install 32-bit Office for existing VBA compatibility
Consider this option when maintaining compatibility with existing 32-bit code is more important than using 64-bit Access.
Use WPS Office for Everyday Office Documents
WPS Office is a free, lightweight alternative with a familiar interface and support for common Microsoft Office formats, making it easy to move everyday documents between suites. It does not replace Microsoft Access or fix Access VBA code.

Frequently Asked Questions
How do I check whether Access is 32-bit or 64-bit?
In Access, select File > Account > About Access. The information window identifies the installed edition's bitness.
Does 64-bit Windows mean I have 64-bit Access?
No. A 64-bit Windows computer can run either 32-bit or 64-bit Access. Check About Access to confirm which edition is installed.
Should I change every Long in my VBA code to LongPtr?
No. Use LongPtr for pointer-sized values such as handles and pointers; ordinary 32-bit numeric values may still need Long. Check the Windows API documentation for each declaration.
Can the same API declaration support both 32-bit and 64-bit Office?
In VBA7, a correctly written PtrSafe declaration can use LongPtr for pointer-sized values on both editions. If you also support older VBA versions, use #If VBA7 Then and #Else branches for the declarations.
Can WPS Office run my Access database and fix its VBA code?
No. WPS Office does not replace Microsoft Access or repair Access VBA. Use Access and its VBA editor to compile and update the database code.




