Making 32 bit VBA code work under 64-bit - any gotchas other than Declare Functions? (1 Viewer)

AndrewS

Registered User.
Local time
Today, 17:37
Joined
Feb 21, 2017
Messages
30
Some users here now have whiz-bang new Surface Pros running Windows 10 64 bit, and 64 bit Office.

When they try to use the Access database I look after, they get a "the code in this project must be updated for use on 64-bit systems" error.

Reading on this forum and elsewhere, this relates to Declare statements.

This post pointed me to fixing the immediate issue, by wrapping the declare functions thus:
Code:
#If Win64 Then
  Private Declare PtrSafe Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
                      (ByVal IpBuffer As String, nSize As Long) As Long
  Private Declare PtrSafe Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" _
                      (ByVal lpBuffer As String, nSize As Long) As Long

#Else
  Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
                      (ByVal IpBuffer As String, nSize As Long) As Long
  Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" _
                      (ByVal lpBuffer As String, nSize As Long) As Long
#End If

To save anyone else wondering what the Win64 is, it's apparently a "compiler constant" set by the environment.

Whether the Longs need to be changed to LongLong or LongPtr, or can be left as Long, seems rather opaque, and apparently varies from API to API. I was intending trying each in turn, but for this example, Access seems happy enough with leaving it as just Long.

I'm intrigued why our lovely friends at Microsoft decided that merely adding "PtrSafe" should make it work in a 64-bit environment, rather than just having VBA assume PtrSafe...

Has anyone come across any other gotchas with using Access in a mixed 32-bit and 64-bit environment?
 

isladogs

MVP / VIP
Local time
Today, 17:37
Joined
Jan 14, 2017
Messages
18,241
Converting APIs for 64-bit is more complicated than the example you gave.
There are several good guides available online.

For example:
http://codekabinett.com/rdumps.php?Lang=2&targetDoc=windows-api-declaration-vba-64-bit

Another gotcha is that some ActiveX controls don't work in 64-bit Access
e.g. Flexgrid / Treeview (one of them)
The solution to that is of course avoid using ActiveX controls as they can cause issues in different Access versions anyway.
 

AndrewS

Registered User.
Local time
Today, 17:37
Joined
Feb 21, 2017
Messages
30
Thanks ridders. Wish I'd found that link amid all the noise that Mr Google returned! Very clear. Bookmarked for future reference.
 

Users who are viewing this thread

Top Bottom