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  
 
 
Export an Access SQL Statement Data
By Richard Rost   Richard Rost on Twitter Richard Rost on LinkedIn Email Richard Rost   7 years ago

export access dataOne of my Insider Circle students, Nicole, has been using my technique for building dynamic SQL statements to populate her list boxes, like I show in my Access Search Seminar.

She has a great SQL statement all built with the right parameters for her search criteria, and her listbox shows the right records, but now she wants to export that set of records to Excel (for several reasons). Here's my solution:

OK, so you've built an SQL statement for your listbox to show exactly the results you want. Let's say:

MyListBox.RowSource = "SELECT ID, FirstName, LastName FROM CustomerT WHERE LastName=""Rost"""

Now what you want to do is export the results of that to an Excel spreadsheet.

Here's a simple solution: build a REPORT that has the same fields in it that your table has, laid out in a spreadsheet-like format (just as you'd want to see in Excel).

Now, open that report with a Docmd.OpenReport command and give it a WhereCondition equal to the WHERE clause of your SQL statement above:

DoCmd.OpenReport "MyReportR", acViewPreview, , "LastName=""Rost"""

Now, you can easily export that report to Excel under EXTERNAL DATA > Export > Excel

This isn't the BEST solution, but it works just fine and has a minimal amount of coding.

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
 

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

10/17/2021Date Only?
10/16/2021Relink Tables
10/16/2021Access Developer 34
10/16/2021Access Developer 34 Lessons
10/16/2021Access Developer 34
10/10/2021Copy Text from Field
10/10/2021Access for Free
10/9/2021Birthdays
10/8/2021Label Resize
10/2/2021Criticisms of Access
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Account Login
Online Theater
Downloads
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: sql search export  PermaLink