Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Search Form 2.0    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Filtering MultiSubforms
James Hopkins 
     
3 years ago
Hey Richard and the Guys, I try to use the method that Richard used in the Search 2.0 Tech Help. When try to Filter Dates but I am using an Combo Box to select the Date Range like: "Today", "Last 7 Days", "Last 14 Days", or Custom Date Range; using two Text Boxes to Enter the "Start & End Dates". What is best way to get this done?
Kevin Robertson  @Reply  
          
3 years ago
From the information provided this is how I would set this up.
Obviously you will have different names for your fields and table/query so change as appropriate.
Kevin Robertson  @Reply  
          
3 years ago

James Hopkins OP  @Reply  
     
3 years ago
Oh Okay Kevin, I will try it.

This is what I had:

Public Function RequeryForm()

    Dim mySQL As String, whereStr As String

    mySQL = "SELECT * FROM HoursLogT "
    whereStr = ""
    
    If Not IsNull(CboDateFilter) Then
        Select Case CboDateFilter
            Case "Today"
                whereStr = "LogHourDate=#" & Date & "# "
                StartDate.Visible = False
                EndDate.Visible = False
                StartDate = Date
                EndDate = Date
            Case "Last 7 Days"
                whereStr = "LogHourDate>=#" & Date - 7 & "# And LogHourDate<=#" & Date & "# "
                StartDate.Visible = False
                EndDate.Visible = False
                StartDate = Date
                StartDate = Date - 7
                EndDate = Date
            Case "Last 14 Days"
                whereStr = "LogHourDate>=#" & Date - 14 & "# And LogHourDate<=#" & Date & "# "
                StartDate.Visible = False
                EndDate.Visible = False
                StartDate = Date
                StartDate = Date - 14
                EndDate = Date
            Case "Last 30 Days"
                whereStr = "LogHourDate>=#" & Date - 30 & "# And LogHourDate<=#" & Date & "# "
                StartDate.Visible = False
                EndDate.Visible = False
                StartDate = Date
                StartDate = Date - 30
                EndDate = Date
            Case "Last 60 Days"
                whereStr = "LogHourDate>=#" & Date - 60 & "# And LogHourDate<=#" & Date & "# "
                StartDate.Visible = False
                EndDate.Visible = False
                StartDate = Date
                StartDate = Date - 60
                EndDate = Date
            Case "Last 90 Days"
                whereStr = "LogHourDate>=#" & Date - 90 & "# And LogHourDate<=#" & Date & "# "
                StartDate.Visible = False
                EndDate.Visible = False
                StartDate = Date
                StartDate = Date - 90
                EndDate = Date
            Case "Last Month"
                whereStr = "Month(LogHourDate)=#" & Date - 30 & "# "
                StartDate.Visible = False
                EndDate.Visible = False
                StartDate = Date
                StartDate = Month(Date) - 30
                EndDate = Month(Date) + 30
            Case "This Month"
                whereStr = "Month(LogHourDate)=#" & Date & "# "
                StartDate.Visible = False
                EndDate.Visible = False
                StartDate = Date
                StartDate = Month(Date)
                EndDate = Month(Date) + 30
             Case "Custom Date Range"
                whereStr = StartDate And EndDate
                StartDate.Visible = True
                EndDate.Visible = True
        End Select
    End If
    
    If whereStr <> "" Then whereStr = " WHERE " & whereStr
    
    mySQL = mySQL & whereStr
    mySQL = mySQL & "ORDER BY LogHourDate"
    RecordSource = mySQL
    
End Function
James Hopkins OP  @Reply  
     
3 years ago
Here's also the Form Setup:
James Hopkins OP  @Reply  
     
3 years ago

James Hopkins OP  @Reply  
     
3 years ago

Kevin Robertson  @Reply  
          
3 years ago
Made some changes based on the additional data.
I added a couple of buttons for This Month & Last Month which show when 'Custom' is selected which will automatically add the StartDate and the EndDate, then requery the form.
Kevin Robertson  @Reply  
          
3 years ago

Kevin Robertson  @Reply  
          
3 years ago

Kevin Robertson  @Reply  
          
3 years ago
I would actually blank out both text boxes when the Combo Box is updated

Add this to the start of the After Update event.
StartDate = ""
EndDate = ""
James Hopkins OP  @Reply  
     
3 years ago
Hey Kelvin, when using Multi-Subform, in the Form's On-Load. Should I put the "RequeryForm" function in each Subform and make it an Public Function to Filter the Subform's Data?
James Hopkins OP  @Reply  
     
3 years ago
Also, we are not using Buttons for the "Last Month" and "This Month". They are in the "CboDateFilter" Combo Box fields.
Kevin Robertson  @Reply  
          
3 years ago
OK. Here is the revised code I came up with so all the filters come from the combo box (no buttons needed).

Note: I did this for a continuous form (no subforms) so you will have to modify the code for your specific needs. It should be enough to get you started.
Kevin Robertson  @Reply  
          
3 years ago

James Hopkins OP  @Reply  
     
3 years ago
If I wanted to Filter the Subforms, I will have the Call th "Requery" Sub in the "Open Load" in each Form.
Kevin Robertson  @Reply  
          
3 years ago
If the subforms are set up correctly, when the one with the date field filters the other 2 should also filter based on there respective IDs.
James Hopkins OP  @Reply  
     
3 years ago
Thanks Kevin, I got it. I had to "FormName.Form.RecordSource = mySQL" for each Form.
James Hopkins OP  @Reply  
     
3 years ago
Kelvin, the Code is working Correctly... Thanks again, but I keep going this:
James Hopkins OP  @Reply  
     
3 years ago

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

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: 4/15/2026 7:15:22 PM. PLT: 1s