First Published 7 Nov 2023 Difficulty level : Moderate
I have been working with both 32-bit and 64-bit Access since 2014 and almost all of my applications are designed to work in both bitnesses.
However, until now I have not written any articles specifically on this topic. I intend to address this oversight with several articles of which this is the first.
From version 2010 onwards, Microsoft Office programs have been available in both 32-bit and 64-bit versions. VBA was updated to version 7 to handle 64-bit declarations.
Users with 32-bit Windows can only install 32-bit Office. However, most users now have 64-bit Windows and can choose which bitness of Office to install
For many years, the default installation was 32-bit and for most users there was little benefit in installing the 64-bit version, with the exception of users with large and complex Excel spreadsheets or highly demanding Access databases.
See Choose between the 64-bit or 32-bit version of Office
Gradually the proportion of 64-bit Office users has increased, particularly since the default installation changed to 64-bit a couple of years ago
64-bit Conversion Issues
For Access developers, there are three main issues to deal with in ensuring applications will run in both bitnesses:
1. All API declarations must be updated for use in 64-bit by adding PtrSafe and changing Long values in handles/pointers to LongPtr
The example below uses conditional compilation and will work in both VBA7 (2010 or later) and older versions
#If VBA7 Then ' Office 2010 or later (32-bit & 64-bit)
Private Declare PtrSafe Function GetDC Lib "user32" (ByVal hWnd As LongPtr) As LongPtr
Private Declare PtrSafe Function ReleaseDC Lib "user32" (ByVal hWnd As LongPtr, ByVal hdc As LongPtr) As Long
Private Declare PtrSafe Function GetDeviceCaps Lib "gdi32" (ByVal hdc As LongPtr, ByVal nIndex As Long) As Long
Private Declare PtrSafe Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
#Else ' Office 2007 or earlier (32-bit only)
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hdc As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
#End If
If all users are running Access 2010 or later, they will all have VBA7 and so conditional compilation is NOT needed.
In such cases, the above code can be simplified to just the portion in the #If VBA7 section:
Private Declare PtrSafe Function GetDC Lib "user32" (ByVal hWnd As LongPtr) As LongPtr
Private Declare PtrSafe Function ReleaseDC Lib "user32" (ByVal hWnd As LongPtr, ByVal hdc As LongPtr) As Long
Private Declare PtrSafe Function GetDeviceCaps Lib "gdi32" (ByVal hdc As LongPtr, ByVal nIndex As Long) As Long
Private Declare PtrSafe Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
A follow-up article will discuss conditional compilation and other 64-bit conversion issues in more detail
2. Some older ActiveX controls do not work in 64-bit e.g. Flexgrid
Developers will need to remove such controls or replace with a 64-bit complatible replacement before deployment
3. Whilst ACCDB files will run in both bitnesses, ACCDE files will only run in the same bitness as they were created.
This means creating separate 32-bit & 64-bit ACCDE files for your users.
The first two points also apply to developers in other Office programs such as Excel
Information & Guidance
Converting from 32-bit to 64-bit is usually not that difficult but it can be very time consuming if you have a lot of API declarations to manage.
Many years ago, Microsoft published a text file containing a list of about 1500 API declarations for use in 32-bit Office:
Visual Basic Win32 API Declarations
An updated version was published for 64-bit compatibility when Office 2010 was released:
Office 2010 Help Files: Win32API_PtrSafe with 64-bit Support
There is a lot of information available online on this topic, not all of it accurate.
The next three articles in this series provide more detailed guidance about different aspects of the conversion process.
In addition, I recommend you look at the following articles, particularly if you only have a few APIs to convert:
Compatibility between the 32-bit and 64-bit versions of Office
Declaring API Functions For 64 Bit Office (And Mac Office)
Interprocess Communication Between 32-bit and 64-bit Applications
How to convert Windows API declarations in VBA for 64-bit
32-bit vs. 64-bit VBA: Deep Dive
Conversion Utilities
If you have a lot of applications to convert and/or a lot of APIs, you may find one or both of the following utilities useful
1. Windows API Viewer for Excel
Despite its name, the information provided is equally applicable to all VBA enabled Office applications.
This is a free, standalone utility created by former Excel MVP, Dennis M. Wallentin back in 2016.
It handles API declarations, type statements and constants
It was hosted for many years on the Excel website of another Excel MVP, Ron de Bruin: Ron de Bruin Excel automation
Unfortunately, in recent months, Ron has removed all the content from his website and the above utility is no longer easily available to download.
With a bit of effort, I was able to locate replacement copies by searching the excellent web archive, The Wayback Machine
With Dennis's permission, I am now hosting the utility here for anyone to download.
NOTE: Choose the correct version to match your Windows (not Office) bitness
Click to download:
a) 64-bit: Windows API Viewer x64 EXE file (zipped) - approx 28 MB
b) 32-bit: Windows API Viewer x86 EXE file (zipped) - approx 28 MB
2. Access 32 to 64 Conversion
This is an ongoing project currently being developed by Peter Cole and available from Access32to64
It includes a free API scanner and Viewer available for download from the above site.
The API viewer works in a similar way to the first utility
The API scanner allows you to search all the APIs in a specified database or folder
The results are then saved to a text file to assist with the process of converting your apllication
If you have a large number of procedures / applications to update, an Access 32 to 64 Updater application is also available from the same site.
NOTE: The Updater is a commercial application. For more details including prices, send an email to: support@thememydatabase.co.uk
Feedback
Please use the contact form below to let me know whether you found this article interesting/useful or if you have any questions/comments.
Please also consider making a donation towards the costs of maintaining this website. Thank you
Colin Riddington Mendip Data Systems Last Updated 7 Nov 2023
Return to Access Articles Page
Page 1 of 5
1
2
3
4
5
Return To Top
|
|