VBA & Macro Problems

Fix Access VBA Code After Moving to 64-Bit Office

Huma Ashraf ChHuma Ashraf Ch Nov 14, 2026 869 views

Question details

Determine why Access VBA code fails on a new computer and make it compatible with the installed Office edition.

Fix Access VBA Code After Moving to 64-Bit Office
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA editor

Open the database in Access and press Alt+F11. Select Debug > Compile to identify the first declaration or line that fails.

2
Find API declarations

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.

3
Update pointer-sized values

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.

4
Add compatibility branches if needed

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.

5
Compile and test

Select Debug > Compile again, resolve any remaining errors, and run the affected database features on each Access edition you need to support.

Update VBA Windows API declarations for 64-bit Access
PtrSafe alone is not enough: A declaration can compile with PtrSafe but still fail if pointer or handle types are incorrect. Check each API signature and its associated code.
Free Microsoft Office alternative

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.

Free, lightweight tools for everyday office workCompatible with Microsoft Word, Excel, and PowerPoint formats, including DOCX, XLSX, and PPTXA familiar interface helps ease the transition from Microsoft OfficeWork with office documents alongside your Access database workflow
microsoft office alternative - wps office

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.