[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 214
  • Last Modified:

main form filter

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
PeterBaileyUk
Asked:
PeterBaileyUk
  • 7
  • 5
1 Solution
 
JezWaltersCommented:
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
 
JezWaltersCommented:
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
 
PeterBaileyUkAuthor Commented:
Thx for the adjustment but is it possible to increment 1 above 100 and get all the years effectively unfiltered
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
JezWaltersCommented:
Have you tried the code I just posted?
0
 
PeterBaileyUkAuthor Commented:
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
 
PeterBaileyUkAuthor Commented:
interesting with the else it goes to 100 then zero thereafter and so cycles
0
 
PeterBaileyUkAuthor Commented:
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
 
PeterBaileyUkAuthor Commented:
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
 
PeterBaileyUkAuthor Commented:
how do i make the filter on the main form what it currently is plus the result of this above?
0
 
JezWaltersCommented:
Can you post a sample database, so I can see what you're trying to do in context?
0
 
PeterBaileyUkAuthor Commented:
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
 
JezWaltersCommented:
Can you upload a cutdown database that shows what you're trying to do instead?
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now