Solved

main form filter

Posted on 2011-03-18
12
192 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
  • 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 500 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
 
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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now