25 hours ago: Power and Internet are out in my office due to Hurricane Ian. Click for details.
 
Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   Seminars   Templates   TechHelp   Fast Tips   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 Twitter Richard Rost on LinkedIn Email Richard Rost   2 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?

Members

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!

Links

Replace Function: https://599cd.com/Replace
Me.RecordSource: https://599cd.com/RecordSource
Double Double Quotes: https://599cd.com/DoubleDouble
SetFocus: https://599cd.com/SetFocus
Intro to VBA: https://599cd.com/IntroVBA

Addendums

  • 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. :)

Extras

Alex's Online SQL to VBA Tool

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

Resources

Mailing List - Get emails when new videos released
Consulting - Need help with your database
Tip Jar - Your tips are graciously accepted

Questions?

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
12 monthsBlank Space after short linesJohn Michael Fowler
15 monthsAddendumRichard Rost
20 monthsSetWarnings ReversedJames Gray

 

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.
 
Subscribe
 

Check out these other pages that may be of interest to you:

9/27/2022Report Border
9/26/2022First Day of Month
9/23/2022Before Update
9/22/2022Synchronize Subforms
9/21/2022InputBox
9/20/2022Link Master Fields
9/19/2022DateSerial
9/18/2022Sequential Annual Coding
9/16/2022Scope
9/15/2022Resize Forms
 
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
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  Convert Query SQL to VBA in Microsoft Access