Solved

main form filter

Posted on 2011-03-18
12
200 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

820 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