Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Help   Contact   Merch   Join   Order   Logon   Forums   
 
Back to Search Form 2.0    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Print Out SQL String
Jan Zimmermann 
   
2 months ago
How can I print out the data selected by SQL string via a print button on the form. Report is alreadz furnished
Sandra Truax  @Reply  
         
2 months ago
Jan Zimmermann OP  @Reply  
   
2 months ago
Thanks. The SQL string has two WHERE conditions. I've slso tried it with recordsets. It didn't work.
Jan Zimmermann OP  @Reply  
   
2 months ago
It's based on Check Form 2.0
Kevin Robertson  @Reply  
           
2 months ago
Jan An SQL string should have only one WHERE condition.
Jan Zimmermann OP  @Reply  
   
2 months ago
WHERE YEAR = 2026 AND Month = 6
It works
Alex Hedley  @Reply  
           
2 months ago
What didn't work?
Jan Zimmermann OP  @Reply  
   
2 months ago
I have a form with a subform and a corresponding report. The parent form contains two boxes: YearCombo and MonthCombo.

When the subsequent PrintBtn function is used, for example, to select 2026 and 6, it displays the correct values in the first column of the report, but the report then continues to show all months.
SQL statement:

DetailsPrivate Sub PrintBtn_Click()
    Dim SQL As String, WhereStr As String, OrderBy As String

    WhereStr = ""
    If YearCombo <> "" Then
        If WhereStr <> "" Then WhereStr = WhereStr & " AND "
        WhereStr = WhereStr & "Jahr = " & YearCombo

    End If
    If MonthCombo <> "" Then
        If WhereStr <> "" Then WhereStr = WhereStr & " AND "
        WhereStr = WhereStr & "MonatID= " & MonthCombo
    End If

     SQL = "SELECT * FROM tblExpenses"

    If WhereStr <> "" Then
        SQL = SQL & " WHERE " & WhereStr
    End If
''''
'''''    SQL = SQL & " ORDER BY " & SortField
'''''    If SortHow = "Z-A" Then SQL = SQL & " DESC"
''''
    SQL = SQL
    SQL2 = SQL
    Me.RecordSource = SQL

    SQL = Me.Filter

    
    DoCmd.OpenReport "repNeu - Copy", acViewReport, penArgs:=Me.RecordSource

End Sub

Jan Zimmermann OP  @Reply  
   
2 months ago

Jan Zimmermann OP  @Reply  
   
2 months ago
Solved it. Set the combo boxes directly to the query. No SQL. Thanks to all!
Richard Rost  @Reply  
           
2 months ago
Glad you got it working, Jan. Using the combo boxes as criteria directly in the report's underlying query is usually the simplest solution when the report is already designed.

For a report, I would generally avoid changing the form's RecordSource just to print. Let the report's query read the values from YearCombo and MonthCombo, then open the report. Nice job troubleshooting it.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Search Form 2.0.
 

Next Unseen

 
 
What's This?

 

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: 9/5/2026 7:28:01 PM. PLT: 1s