Free Lessons
Fast Tips
Topic Index
Home   Courses   Index   Templates   Seminars   TechHelp   Forums   Help   Contact   Join   Order   Logon  
Home > TechHelp > Directory > Access > SQL to VBA < Alpha Grouping | Fast Form Update >
Convert Query SQL to VBA
By Richard Rost   Richard Rost on LinkedIn Email Richard Rost   4 years ago

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

 S  M  L  XL  FS  |  Slo  Reg  Fast  2x  |  Bookmark 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 view Extended Cut videos, when available. 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 register on my YouTube Find User page 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:


  • A few of my students have pointed out that the conversion doesn't work properly if you have spaces in your table or field names. Of course, to each of them I have pointed out that one of the very first things I teach in Access Beginner Level 1 is NOT to use spaces in your table or field names - or any object name for that matter. It complicates things. This is one example of that. Is a fix possible? Sure. Am I going to write one? Nope. :)


Alex's Online SQL to VBA Tool

Learn More

FREE Access Beginner Level 1
FREE Access Quick Start in 30 Minutes
Access Level 2 for just $1

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
Tip Jar - Your tips are graciously accepted


Please feel free to post your questions or comments below or post them in the Forums.


Comments for Convert Query SQL to VBA
Age Subject From
44 daysWhere was this tool when IJeffrey Kraft
11 monthsConvert Query SQL to VBAWilliam Kennedy
3 yearsBlank Space after short linesJohn Michael Fowler
3 yearsAddendumRichard Rost
3 yearsSetWarnings ReversedJames Gray


Start a NEW Conversation
Only students may post on this page. Click here for more information on how you can set up an account. If you are a student, please Log On first. Non-students may only post in the Visitor Forum.
Subscribe to Convert Query SQL to VBA
Get notifications when this page is updated

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.

Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
My Account
My Courses
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
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

Copyright 2024 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 4/15/2024 2:48:54 AM. PLT: 0s
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  Convert Query SQL to VBA in Microsoft Access