Go Back   Access World Forums > Microsoft Access Reference > Sample Databases

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 04-24-2017, 06:50 AM   #1
isladogs
Part time moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 6,860
Thanks: 92
Thanked 1,689 Times in 1,568 Posts
isladogs is just really nice isladogs is just really nice isladogs is just really nice isladogs is just really nice isladogs is just really nice
SQL to VBA and back again

Some years ago, the wonderful Allen Browne created a small utility called Sql2vba
See 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.
"

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.
Useful for testing when the VBA string is long & complex as shown below







To use this, just copy the form frmSql2vba & the 2 modules modFunctions & modResizeForm to your own database

The latter module contains code originally by Jamie Czernak used to automatically resize forms depending on users' screen resolution.
If you don't want to use that part:
a) omit the module modResizeForm
b) remove the line ResizeForm Me from the frmSql2vba Form_Open procedure

Any comments welcomed.
Attached Images
File Type: png #Query1.PNG (39.0 KB, 1518 views)
File Type: png SQL.PNG (39.1 KB, 1497 views)
File Type: png vba.PNG (43.7 KB, 1689 views)
Attached Files
File Type: accdb SQL2VBA.accdb (488.0 KB, 458 views)

__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Colin
Previously known as ridders : Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by isladogs; 05-21-2017 at 09:40 AM. Reason: Added inline images
isladogs is offline   Reply With Quote
The Following 4 Users Say Thank You to isladogs For This Useful Post:
gleesonc (07-05-2017), NauticalGent (05-02-2017), Scribtor (10-10-2018), usm01 (07-08-2017)
Old 05-08-2017, 02:09 AM   #2
Gasman
Access newbie
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 2,574
Thanks: 307
Thanked 401 Times in 386 Posts
Gasman has a spectacular aura about Gasman has a spectacular aura about
Re: SQL to VBA and back again

Hi Colin,
Thanks very much for this. I spend a fair bit of time creating a query in the designer and then try and amend for VBA.

Just for your info the display for the resize is a little off on my screen running at 1920*1080. The form is still usable, but thought I'd let you know.

Please see attached.
Attached Images
File Type: png sql2vba.png (76.0 KB, 145 views)
__________________
Access novice. Sometimes trying to give something back.
Access 2007
Gasman is offline   Reply With Quote
Old 10-25-2017, 05:09 AM   #3
isladogs
Part time moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 6,860
Thanks: 92
Thanked 1,689 Times in 1,568 Posts
isladogs is just really nice isladogs is just really nice isladogs is just really nice isladogs is just really nice isladogs is just really nice
Re: SQL to VBA and back again

Thanks for the info Gasman
By chance I have a secondary monitor with exactly that resolution.

Have modified the form size slightly & it now seems to be fine.

NOTE for other users:
No other changes made
If the earlier version worked for you, there is no need to download this
Attached Files
File Type: accdb SQL2VBA.accdb (492.0 KB, 199 views)

__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Colin
Previously known as ridders : Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
isladogs is offline   Reply With Quote
Old 10-25-2017, 07:02 AM   #4
Gasman
Access newbie
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 2,574
Thanks: 307
Thanked 401 Times in 386 Posts
Gasman has a spectacular aura about Gasman has a spectacular aura about
Re: SQL to VBA and back again

Thank you Colin.
I obviously have something wrong with my system. the new version hides the buttons even more.

I 've now amended the form, to fit on my system by changing the tab size. Thank you for leaving it to be able to be amended.
Attached Images
File Type: png design mode.PNG (15.4 KB, 121 views)
File Type: png form mode.PNG (12.2 KB, 114 views)
__________________
Access novice. Sometimes trying to give something back.
Access 2007
Gasman is offline   Reply With Quote
Old 11-14-2017, 09:31 AM   #5
isladogs
Part time moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 6,860
Thanks: 92
Thanked 1,689 Times in 1,568 Posts
isladogs is just really nice isladogs is just really nice isladogs is just really nice isladogs is just really nice isladogs is just really nice
Re: SQL to VBA and back again

I've just done a few minor tweaks & bug fixes to this utility (its now on v3.02 ....though the screenshot says 3.01!)

Main changes:
a) Fixed error 2046 that recently appeared when clicking 'Copy Active Window' button. It used to be fine . . .
b) Added the option to start the VBA statement generated with CurrentDB.Execute or DoCmd.RunSQL according to user preference



The eagle eyed will notice I've swopped the tab order so SQL is now on the left as its the usual starting point for most people using this.
Attached Images
File Type: png Capture.PNG (23.0 KB, 890 views)
Attached Files
File Type: zip SQL2VBA.zip (76.6 KB, 147 views)
__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Colin
Previously known as ridders : Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by isladogs; 11-14-2017 at 09:36 AM.
isladogs is offline   Reply With Quote
Old 09-28-2018, 02:42 AM   #6
isladogs
Part time moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 6,860
Thanks: 92
Thanked 1,689 Times in 1,568 Posts
isladogs is just really nice isladogs is just really nice isladogs is just really nice isladogs is just really nice isladogs is just really nice
Re: SQL to VBA and back again

I've just updated this to v3.03.
This fixes an issue with the Copy to Clipboard API in 64-bit Access.
Attached Files
File Type: zip Sql2vba.zip (70.4 KB, 44 views)
__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Colin
Previously known as ridders : Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
isladogs is offline   Reply With Quote
The Following User Says Thank You to isladogs For This Useful Post:
eizik_g (11-10-2018)
Old 10-08-2018, 10:47 PM   #7
Scribtor
Newly Registered User
 
Join Date: Sep 2018
Posts: 16
Thanks: 8
Thanked 0 Times in 0 Posts
Scribtor is on a distinguished road
Re: SQL to VBA and back again

Simply awesome!


If I only had this earlier, it would've made my life so much easier!

Thanks a bunch for this!!!

Scribtor is offline   Reply With Quote
Old 10-09-2018, 01:07 PM   #8
isladogs
Part time moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 6,860
Thanks: 92
Thanked 1,689 Times in 1,568 Posts
isladogs is just really nice isladogs is just really nice isladogs is just really nice isladogs is just really nice isladogs is just really nice
Re: SQL to VBA and back again

Glad you found it useful....

__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Colin
Previously known as ridders : Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
isladogs is offline   Reply With Quote
Reply

Tags
sql , vba

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help I Need Ideas, Setup Local Back-end that Updates Server Back-end panthers1788 General 1 07-02-2013 12:15 AM
Back to back Ashes Series 2013 SpentGeezer Politics & Current Events 4 01-10-2013 08:38 PM
is there any way of getting them back? kevinasam Other Software 1 12-28-2011 03:45 PM
run repors back to back mrrayj60 Reports 4 08-11-2010 11:51 PM
Can't get into back end PaulJK General 3 11-20-2002 12:20 PM




All times are GMT -8. The time now is 11:41 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Sponsored Links

How to advertise

Media Kit


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World