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 Developer Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Writing a Report with the Same SQL Filter
Robert Allen 
     
3 months ago
I have a database (for engineering drawings) that uses 7 different filters on a continuous form by building an SQL statement.

I would like to generate a report using the same filters.
I have tried Me.Filter = Forms!DwgSearchF.Filter, but that does not use the SQL filters.
I have tried DoCmd.OpenReport, but I am not sure if it is possible to pass the SQL Where statement or how.
The filters are:
Private Sub AreasFilter_AfterUpdate()
    RequeryForm
End Sub

Private Sub ClassFilter_AfterUpdate()
    RequeryForm
End Sub

Private Sub RemarkFilter_AfterUpdate()
    RequeryForm
End Sub

Private Sub SubjectsFilter_AfterUpdate()
    RequeryForm
End Sub

Private Sub EquipFilter_AfterUpdate()
    RequeryForm
End Sub

Private Sub KeywordFilter_AfterUpdate()
    RequeryForm
End Sub

Private Sub ByFilter_AfterUpdate()
    RequeryForm
End Sub

The sub to build the SQL statement ends like this:
...
If RemarkFilter <> "" Then
        If WhereStr <> "" Then WhereStr = WhereStr & " AND "
        WhereStr = WhereStr & "REMARK Like ""*" & RemarkFilter & "*"""
    End If
    
    SQL = "SELECT * FROM DrawingT"
    SQL2 = SQL

    If WhereStr <> "" Then      'If a WHERE string exists, add it to the SQL statement
        SQL = SQL & " WHERE " & WhereStr
    End If
    Me.RecordSource = SQL
    SQL2 = SQL
End Sub

Thanks for your help.
Adam Schwanz  @Reply  
           
3 months ago
Search Form 2.0

You can do it the same way you do with a form. Here's one example of where I use it after building the SQL

        If Wh = "" Then
            DoCmd.OpenReport "MyReport", acViewPreview
        Else
            DoCmd.OpenReport "MyReport", acViewPreview, , Wh
        End If
Robert Allen OP  @Reply  
     
3 months ago
Adam,
Thanks for the help.  I made it too complicated.
I had put some code in the OnOpen event that evidently messed with the SQL Where statement.
I really appreciate your very quick response.
Robert
Raymond Spornhauer  @Reply  
          
3 months ago
When you modify the Filter on a Form or Report, you also need to use:

FilterOn = True

-Raymond
Raymond Spornhauer  @Reply  
          
3 months ago
Another option:

Don't use the Form Filter Property.  Update the SQL Statement.

Then when you open your Report, you can set the Report.Recordsource = Form.Recordsource

-Raymond

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developer 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: 5/6/2026 2:48:27 PM. PLT: 1s