Solved

main form filter

Posted on 2011-03-18
12
195 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS Access 2007 Count Unique Values in a Group 5 33
ms/access ftp / SFTP 3 32
Password on a button in Access 2013 7 34
count unique records in access report 2 23
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
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…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

912 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

14 Experts available now in Live!

Get 1:1 Help Now