Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Using VBA to open a Report
William Kennedy 
    
3 years ago
I have a lot of Queries that generate reports. Too many.  How can I use VBA that is equal to the Query SQL to open the report with that VBA code.
Juan C Rivera  @Reply  
            
3 years ago
Access Developer Level 13
or look up select case for a quick ref.

Scott Axton  @Reply  
        
3 years ago
First, before you make any changes, BACK UP YOUR DATABASE!

Go to the query that is for your report. In design mode switch to the SQL view and copy the SQL.

Open your report in design view and find the Record Source in the properties.  Remove the query and paste in the SQL you just copied. (Shift-F2 will zoom in if you want to look at it).

Save it and run it.  You should get the same results you are expecting.
Just in case you didn't already do it to start - BACK UP YOUR DATABASE!

You can now delete your query.  
Something to note:  If the same query is used in other places like for forms or other reports, you will need to make the changes in those as well.

Did I mention BACK UP YOUR DATABASE! before you start?

(Sorry it's late and been a long week.  Seriously though, it's easier to go back if something does go wrong than to recreate it from scratch.)

Take  a look at the
Record Source
Report Listbox as well.  Those may be of help.
If you have the same basic report but just one minor change consider using Value From a Form to reduce the number of reports / queries.

Seriously look into purchasing the Access SQL Seminars 1 & 2 at a minimum.
William Kennedy OP  @Reply  
    
3 years ago
Thanks Scott,  I ordered Seminar 1 but for some reason it has not been released yet.  Sent an email to Richard.  Maybe I did it wrong.
Alex Hedley  @Reply  
           
3 years ago
SQL1 is showing on your account
Maybe logout and log back in
William Kennedy OP  @Reply  
    
3 years ago
Thanks Scott.  I use an accounts table.  Typical Bank Account table, Debit/Credit style.  I use a Query to generate a Running Balance Report.  I use another query that selects the previous query's last record; this is used to make a report indicating the last Date and Balance within that account table.  
I can use SQL to generate the Running Balance Report but how do I generate the last Date and Balance Report without that previous query. Is there a SQL that will do that?
Juan C Rivera  @Reply  
            
3 years ago
William the SQL will do what you need it to do but you must understand SQL in order to build what you need done.  Like Scott said back up and try I have done some SQL that damaged my database to the point that I had to trash it and go back to my backup.  If you are asking for someone to write it for you then provide more info.  The team here is more than happy to set you up but like the saying says "give a fish you eat one night, teach to fish you eat every night".  Unless there is a must get this done right now suituation, do the course and try it.  When you figure this out you will be amazed and say to yourself "WOW Im good"...

Stick with it and remenber we are here if you get stuck

V/r
Juan
Scott Axton  @Reply  
        
3 years ago
William  
Just cheat.  LOL  
I do it all of the time honestly. I myself am terrible at writing SQL statements "on the fly" especially the complicated ones.
You say that your second report is based on the results of the first query correct?
Assuming that everything is working correctly, how did you get the last date and balance?  Just by looking at it?

Here is the cheat:  Look at the SQL of the second query and let Access tell you what the SQL is.

In other words Access is going to convert the first query and add in your Last Date and Balance criteria.

Be aware that setting the SQL in the record source does have limits.  I believe that the limit is 256 characters if I remember correctly.  If your query is based on a single table clean up the Table.Field and just keep Field like Richard has shown in other videos.  

You are quickly getting into the VBA arena of needs but I encourage you to not get to far ahead of your learning.
For now - To get this working with a single button click you just need to put both queries into the button macro.
Go back to Access Expert 15 Lesson 3 for an example.  Richard show's running an Append query but you can run a select query as well.  More importantly you can run multiple queries in one Macro.
Just pick the first Select Query for the open query, then add in a second open query for the second one.  The one button can run the two queries back to back.
William Kennedy OP  @Reply  
    
3 years ago
Thanks Juan an Scott.  Reviewing all your help now.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

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

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
PCResale.NET
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
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 6/17/2026 12:11:05 PM. PLT: 1s