Version 3.23 Approx 0.6 MB First Published 28 Sept 2018 Last Updated 14 Apr 2023
Some years ago, the wonderful Allen Browne created a small utility called Sql2vba.
It is available from his website: http://allenbrowne.com/ser-71.html
The purpose was to save developer time:
"Rather than typing complex query statements into VBA code, developers often mock up a query graphically, switch it to SQL View, copy, and paste into VBA.
If you've done it, you know how messy it is sorting out the quotes, and the line endings.
Solution: create a form where you paste the SQL statement, and get Access to create the SQL string for you."
When I started developing in Access, I found this so useful that I extended the idea to work in the other direction as well: VBA to SQL so I could easily create & load a query based on VBA code. This is useful for testing when the VBA string is long & complex as shown below.
With Allen's permission, I am publishing my version of his utility here.
To use this utility, copy the form frmSql2vba & the 2 modules modFunctions & modResizeForm to your own applications
The latter module contains code originally by Jamie Czernak used to automatically resize forms depending on users' screen resolution.
For more details about this feature, see my article:
Automatic Form Resizing - A Tutorial
If you don't want to use that feature:
a) omit the module modResizeForm
b) remove the line ResizeForm Me from the frmSql2vba Form_Open procedure
Click to download: SQL to VBA and back again Version 3.23 (zipped)
3.03 - 28 Sept 2018: fixed issue with Copy to Clipboard code in 64-bit Access
3.23 - 14 Apr 2023: minor bug fixes mainly to remove legacy code no longer used
Please use the contact form below to let me know whether you found this article interesting/useful or if you have any questions/comments.
Do let me know if you find any bugs in the application.
Please also consider making a donation towards the costs of maintaining this website. Thank you
Colin Riddington Mendip Data Systems Last Updated 14 Apr 2023
Return to Example Databases Page
Return to Top