Access 2007-2019
Access 2000-2003
Access Seminars
TechHelp Support
Tips & Tricks
Access Forum
Course Index
Topic Glossary
Insider Circle
Home   Courses   Seminars   Templates   Help   TechHelp   Forums   Contact   Join   Order   Logon  
Home > Help > TechHelp > Directory > Access > SQL to VBA < Alpha Grouping | Fast Form Update >
Convert Query SQL to VBA
By Richard Rost   Richard Rost on Twitter Richard Rost on LinkedIn Email Richard Rost   4 months ago

Convert Query SQL to VBA Code. Add Line Breaks, Quotes, More.

 S  M  L  XL  FS  Join Now

Do you copy a lot of SQL from the query designer SQL view over to the VBA editor to use in your code, and you spend a lot of time "fixing" the string, adding line continuation characters, adding quotes, etc. Well, in this video we'll make a little utility you can use to perform that task with one click. You can use this in a RunSQL statement or a Me.RecordSource change.

John from Hancock, New Hampshire (a Silver Member) asks: Is there a way to format the SQL text of a query with the proper line breaks and quotes so I can copy it to my VBA editor for a RunSQL command without doing all that manual editing?


I'll walk you through some additional modifications to the utility, including splitting long lines up, loading a listbox with all of the queries in the database, and one-click to copy the SQL to the editor textbox and convert it.

Silver Members and up get access to an Extended Cut of this video. Gold Members can download the database template from class plus get access to the Code Vault. If you signed up on YouTube you have to contact me so I can set up your account here on my web site. If you're not a member, Join Today!


Replace Function:
Double Double Quotes:
Intro to VBA:

Learn More

FREE Access Beginner Level 1
Access Level 2 for $1.00

Free Templates

TechHelp Free Templates
Blank Template
Contact Management
Order Entry & Invoicing
More Access Templates


Mailing List - Get Emails When New Videos Released!
Consulting - Need Help with Your Database?


Please feel free to post your questions or comments below or submit them via the TechHelp page.


SetWarnings Reversed Upload Images   Link 
James Gray 
3 months ago
I noticed that the VBA code constructed via the utility has the Set Warnings True statement first instead of Set Warning False.   I think the problem is with the construction of Status function.  I fixed it by changing the order of construction for StatusBox to: StatusBox = StatusBox & vbNewLine & S instead of: StatusBox = s & vbnewline & Statusbox.  Do I have this correct?
Richard Rost
3 months ago
You may indeed be correct. I didn't notice it. I'll check the video when I have some free time, but what you're saying sounds about right. Thanks. :)
Scott Axton
2 months ago
I can confirm that this is the case.  I just noticed it as well.
It is because of how the string is written to StatusBox.  The last command coming in at the top.

It's difficult to see because in the vba code it is written correctly the way access would normally treat it.
  Set Warnings False
  SetWarnings True
Now read the same above from the bottom up
Add a Reply

Start a NEW Conversation
Only students may post right now. Click here for more information on how you can set up an account. If you are a student, please LOG ON first.

You may want to read these articles from the 599CD News:

4/8/2021Age, Part 2
3/30/2021Accounts Receivable
3/28/2021Time & Billing
3/28/2021Time & Billing Template
3/28/2021Time & Billing Lessons
3/28/2021Time & Billing Seminar
3/28/2021Access Developer 28
3/27/2021Send Email
3/24/2021Multi-Table Update
3/23/2021Profit & COGS

Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Account Login
Online Theater
Lost Password
Student Databases
Change Email
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Customer Support
Web Site Tour
Consulting Services
Affiliate Program
Richard Rost
Free Lessons
Mailing List
Video Tutorials
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Terms of Sale
Contact Info
Support Policy
Email Richard
Mailing Address
Phone Number
Fax Number
Course Survey
Blog RSS Feed    Twitter

YouTube Channel    LinkedIn
Keywords: TechHelp Access line breaks, vbnewline, vbtab, sql to vba, convert sql, convert to vba, line continuation character, runsql, recordsource, setfocus, copy to clipboard  PermaLink