DEV Community

Stefano Ferrari
Stefano Ferrari

Posted on

1

VBA 32-bit/64-bit

In the last few years, I built a good number of applications using MSAccess and all the useful tools it has.
Ok, the title of this post may be a little strange because sincerely, who are still using an old 32-bit version? We are in 2020! In my case, I have some small clients that have for example old warehouse machinery that they need to integrate into the management system linking them to a server. So what happens is that we can have a system with, for example, 10 pc with a 64-bit version and 1 with a 32-bit version. This is a problem especially if you have built an auto-update system. So, I searched for a solution that could help me to fix this issue. The problem for me was that the declaration statement of a function in a module is different for the 2 versions, or rather in the 64-bit version, you have to add the keyword PtrSafe to the declaration statement. Microsoft ensures that adding the PtrSafe keyword, the declaration statement will work in both versions but at some conditions. So, when I built the first version in 32-bit, I had this declaration statement:

Declare Function aht_apiGetOpenFileName Lib "comdlg32.dll" _
    Alias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As Boolean
Enter fullscreen mode Exit fullscreen mode

And now I must change it with:

Declare PtrSafe Function aht_apiGetOpenFileName Lib "comdlg32.dll" _
    Alias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As Boolean
Enter fullscreen mode Exit fullscreen mode

Pretty simple. But as Microsoft said in this article, if I want to continue to use the rest of the 32-bit code, it has to respect some conditions. So I decide to use the If statement of the Microsoft Article as I haven't a large number of Functions declared in that way. This is the final result:

#If VBA7 Then
Declare PtrSafe Function aht_apiGetOpenFileName Lib "comdlg32.dll" _
    Alias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As Boolean

#Else

Declare Function aht_apiGetOpenFileName Lib "comdlg32.dll" _
    Alias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As Boolean

#End If
Enter fullscreen mode Exit fullscreen mode

Thank you for reading.

AWS Q Developer image

Build your favorite retro game with Amazon Q Developer CLI in the Challenge & win a T-shirt!

Feeling nostalgic? Build Games Challenge is your chance to recreate your favorite retro arcade style game using Amazon Q Developer’s agentic coding experience in the command line interface, Q Developer CLI.

Participate Now

Top comments (0)

Redis image

Short-term memory for faster
AI agents

AI agents struggle with latency and context switching. Redis fixes it with a fast, in-memory layer for short-term context—plus native support for vectors and semi-structured data to keep real-time workflows on track.

Start building

Debugging and Monitoring Basics for Builders

What is monitoring, and why does it matter for your hackathon project? In this kickoff session, we’ll cover the basics of debugging and introduce you to tools like Sentry that help you catch issues early. Learn how to make your app more stable, secure, and future-proof—so it’s not just ready for submission, but ready for whatever comes next.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️