?
Solved

main form filter

Posted on 2011-03-18
12
Medium Priority
?
205 Views
Last Modified: 2012-05-11
I have some code that gradually increments to 100 in steps

1 to 4 steps of 1
5 to 14 steps of 5
25 to 100
steps of 25

this gives me ranges for year filtering
what I would like is an additional range that gives me all records so if the date selector goes to all their is no date filter but not sure how to implement.

the main form has two buttons + and - to adjust the year range but to option for all
i envisaged after 100 that the next choice is all.


Private Sub BtnMainFormIntroDatePlus_Click()
Dim datestr As String
Select Case MainFormIntroCount
     Case 0 To 4
      MainFormIntroCount = MainFormIntroCount + 1
        LblIntroMainFormCount.Caption = MainFormIntroCount
      
    Case 5 To 14
     MainFormIntroCount = MainFormIntroCount + 5
       LblIntroMainFormCount.Caption = MainFormIntroCount
    Case 15 To 24
    
     MainFormIntroCount = MainFormIntroCount + 10
     LblIntroMainFormCount.Caption = MainFormIntroCount
      Case 25 To 75
     MainFormIntroCount = MainFormIntroCount + 25
    LblIntroMainFormCount.Caption = MainFormIntroCount
    
     Case Else
    ' do nothing
         
     End Select
      
    
      
    datestr = "#" & Format(DateAdd("YYYY", MainFormIntroCount * -1, Now()), "dd/mm/yyyy") & "#"
      
    Forms!cw_client_matching_form.Filter = "([Intro Date]>=" & datestr & ")"

    Me.FilterOn = True
    Me.Requery
    RequeryFilterOffForm
End Sub

Open in new window

0
Comment
Question by:PeterBaileyUk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
12 Comments
 
LVL 17

Expert Comment

by:JezWalters
ID: 35164386
All dates that are delimited by #'s must be American format (i.e. mm/dd/yy), so your format statement is wrong.

Also, if this code in the form "cw_client_matching_form" your current code can be simplified to:
Private Sub BtnMainFormIntroDatePlus_Click()

    Dim datestr As String

    Select Case MainFormIntroCount
        Case 0 To 4
            MainFormIntroCount = MainFormIntroCount + 1
            LblIntroMainFormCount.Caption = MainFormIntroCount
        Case 5 To 14
            MainFormIntroCount = MainFormIntroCount + 5
            LblIntroMainFormCount.Caption = MainFormIntroCount
        Case 15 To 24
            MainFormIntroCount = MainFormIntroCount + 10
            LblIntroMainFormCount.Caption = MainFormIntroCount
        Case 25 To 75
            MainFormIntroCount = MainFormIntroCount + 25
            LblIntroMainFormCount.Caption = MainFormIntroCount
     End Select

    datestr = "#" & Format(DateAdd("yyyy", MainFormIntroCount * -1, Date), "mm/dd/yyyy") & "#"

    Filter = "[Intro Date] >= " & datestr

    FilterOn = True
    Requery
    RequeryFilterOffForm

End Sub

Open in new window

0
 
LVL 17

Accepted Solution

by:
JezWalters earned 2000 total points
ID: 35164400
As for your question, how about the following?
Private Sub BtnMainFormIntroDatePlus_Click()

    Dim datestr As String

    Select Case MainFormIntroCount
        Case 0 To 4
            MainFormIntroCount = MainFormIntroCount + 1
            LblIntroMainFormCount.Caption = MainFormIntroCount
        Case 5 To 14
            MainFormIntroCount = MainFormIntroCount + 5
            LblIntroMainFormCount.Caption = MainFormIntroCount
        Case 15 To 24
            MainFormIntroCount = MainFormIntroCount + 10
            LblIntroMainFormCount.Caption = MainFormIntroCount
        Case 25 To 75
            MainFormIntroCount = MainFormIntroCount + 25
            LblIntroMainFormCount.Caption = MainFormIntroCount
        Case Else
            MainFormIntroCount = Null
            LblIntroMainFormCount.Caption = All
    End Select

    If IsNull(MainFormIntroCount) Then
        Filter = ""
        FilterOn = False
    Else
        datestr = "#" & Format(DateAdd("yyyy", MainFormIntroCount * -1, Date), "mm/dd/yyyy") & "#"
        Filter = "[Intro Date] >= " & datestr
        FilterOn = True
    End If

    Requery
    RequeryFilterOffForm

End Sub

Open in new window

0
 

Author Comment

by:PeterBaileyUk
ID: 35164410
Thx for the adjustment but is it possible to increment 1 above 100 and get all the years effectively unfiltered
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 17

Expert Comment

by:JezWalters
ID: 35164447
Have you tried the code I just posted?
0
 

Author Comment

by:PeterBaileyUk
ID: 35164489
your 2nd reply wasnt there when i responded earlier, just tried and the mainformintrocount is a global integer so cannot be null, neither can it be zero at present because the case says zero I have added the minus code here so you can see whats happening


Private Sub BtnMainFormIntroDateMinus_Click()
Select Case MainFormIntroCount
    
     
    Case 2 To 5
        MainFormIntroCount = MainFormIntroCount - 1
     Case 6 To 15
        MainFormIntroCount = MainFormIntroCount - 5
        
    Case 16 To 25
        MainFormIntroCount = MainFormIntroCount - 10
     Case 26 To 100
        MainFormIntroCount = MainFormIntroCount - 25
    Case Else
    ' do nothing
 End Select
      
      LblIntroMainFormCount.Caption = MainFormIntroCount
      
      
'     Forms!cw_client_matching_form.Filter = "([Intro Date]>=dateadd(""Y"",MainFormIntroCount*-1,now()))"
'
'    Me.FilterOn = True
'    Me.Requery
'    RequeryFilterOffForm
      
      
      
      
      
      
      
End Sub

Private Sub BtnMainFormIntroDatePlus_Click()

    Dim datestr As String

    Select Case MainFormIntroCount
        Case 0 To 4
            MainFormIntroCount = MainFormIntroCount + 1
            LblIntroMainFormCount.Caption = MainFormIntroCount
        Case 5 To 14
            MainFormIntroCount = MainFormIntroCount + 5
            LblIntroMainFormCount.Caption = MainFormIntroCount
        Case 15 To 24
            MainFormIntroCount = MainFormIntroCount + 10
            LblIntroMainFormCount.Caption = MainFormIntroCount
        Case 25 To 75
            MainFormIntroCount = MainFormIntroCount + 25
            LblIntroMainFormCount.Caption = MainFormIntroCount
        Case Else
            MainFormIntroCount = 0
            LblIntroMainFormCount.Caption = All
    End Select

    If IsNull(MainFormIntroCount) Then
        Filter = ""
        FilterOn = False
    Else
        datestr = "#" & Format(DateAdd("yyyy", MainFormIntroCount * -1, Date), "mm/dd/yyyy") & "#"
        Filter = "[Intro Date] >= " & datestr
        FilterOn = True
    End If

    Requery
    RequeryFilterOffForm

End Sub

Open in new window

0
 

Author Comment

by:PeterBaileyUk
ID: 35164499
interesting with the else it goes to 100 then zero thereafter and so cycles
0
 

Author Comment

by:PeterBaileyUk
ID: 35164515
trying this

Private Sub BtnMainFormIntroDatePlus_Click()

    Dim datestr As String

    Select Case MainFormIntroCount
        Case 0 To 4
            MainFormIntroCount = MainFormIntroCount + 1
            LblIntroMainFormCount.Caption = MainFormIntroCount
        Case 5 To 14
            MainFormIntroCount = MainFormIntroCount + 5
            LblIntroMainFormCount.Caption = MainFormIntroCount
        Case 15 To 24
            MainFormIntroCount = MainFormIntroCount + 10
            LblIntroMainFormCount.Caption = MainFormIntroCount
        Case 25 To 75
            MainFormIntroCount = MainFormIntroCount + 25
            LblIntroMainFormCount.Caption = MainFormIntroCount
            
        Case 100
'            MainFormIntroCount = 0
            LblIntroMainFormCount.Caption = "All"
    End Select

    If MainFormIntroCount = 100 Then
        Filter = ""
        FilterOn = False
    Else
        datestr = "#" & Format(DateAdd("yyyy", MainFormIntroCount * -1, Date), "mm/dd/yyyy") & "#"
        Filter = "[Intro Date] >= " & datestr
        FilterOn = True
    End If

    Requery
    RequeryFilterOffForm

End Sub

Open in new window

0
 

Author Comment

by:PeterBaileyUk
ID: 35164551
this is it working fine
Private Sub BtnMainFormIntroDateMinus_Click()
Select Case MainFormIntroCount
    
     
    Case 2 To 5
        MainFormIntroCount = MainFormIntroCount - 1
     Case 6 To 15
        MainFormIntroCount = MainFormIntroCount - 5
        
    Case 16 To 25
        MainFormIntroCount = MainFormIntroCount - 10
     Case 26 To 100
        MainFormIntroCount = MainFormIntroCount - 25
        
        
    
    Case 100 To 101
     MainFormIntroCount = MainFormIntroCount - 1
     
     
     
 End Select
      
      LblIntroMainFormCount.Caption = MainFormIntroCount
      
      
'     Forms!cw_client_matching_form.Filter = "([Intro Date]>=dateadd(""Y"",MainFormIntroCount*-1,now()))"
'
'    Me.FilterOn = True
'    Me.Requery
'    RequeryFilterOffForm
      
      
      
      
      
      
      
End Sub

Private Sub BtnMainFormIntroDatePlus_Click()

    Dim datestr As String

    Select Case MainFormIntroCount
        Case 0 To 4
            MainFormIntroCount = MainFormIntroCount + 1
            LblIntroMainFormCount.Caption = MainFormIntroCount
        Case 5 To 14
            MainFormIntroCount = MainFormIntroCount + 5
            LblIntroMainFormCount.Caption = MainFormIntroCount
        Case 15 To 24
            MainFormIntroCount = MainFormIntroCount + 10
            LblIntroMainFormCount.Caption = MainFormIntroCount
        Case 25 To 75
            MainFormIntroCount = MainFormIntroCount + 25
            LblIntroMainFormCount.Caption = MainFormIntroCount
            
        Case 100
'            MainFormIntroCount = 0
            LblIntroMainFormCount.Caption = "All"
            MainFormIntroCount = MainFormIntroCount + 1
    End Select

    If MainFormIntroCount = 101 Then
'        Filter = ""
'        FilterOn = False
    Else
'        datestr = "#" & Format(DateAdd("yyyy", MainFormIntroCount * -1, Date), "mm/dd/yyyy") & "#"
'        Filter = "[Intro Date] >= " & datestr
'        FilterOn = True
    End If

'    Requery
'    RequeryFilterOffForm

End Sub

Open in new window

0
 

Author Comment

by:PeterBaileyUk
ID: 35164564
how do i make the filter on the main form what it currently is plus the result of this above?
0
 
LVL 17

Expert Comment

by:JezWalters
ID: 35165006
Can you post a sample database, so I can see what you're trying to do in context?
0
 

Author Comment

by:PeterBaileyUk
ID: 35165225
not possible to upload it, the main form filter has been set elsewhere in code. the code line in the above (as it stands)
     Forms!cw_client_matching_form.Filter = "([Intro Date]>=dateadd(""Y"",MainFormIntroCount*-1,now()))"

overwrites the current mainform.filter

what I need is to set the mainform filter to its current state with the addition of the intro date

so

  Forms!cw_client_matching_form.Filter  & "([Intro Date]>=dateadd(""Y"",MainFormIntroCount*-1,now()))"

0
 
LVL 17

Expert Comment

by:JezWalters
ID: 35167025
Can you upload a cutdown database that shows what you're trying to do instead?
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question