Page 1 of 3 123 LastLast
Results 1 to 15 of 31
  1. #1
    Emmanuel is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    272

    Filter not taking effect

    I want to apply a filter using a search button which i applied the folowung codes:


    # Sub Search()Dim strCriteria, task As String


    If Trim(Me.cboIncomeType.Value & vbNullString) = vbNullString Then
    MsgBox prompt:="Please select Payment mode.", buttons:=vbInformation, title:="SOFTWARE"
    Me.cboIncomeType.SetFocus
    Exit Sub

    End If

    If Trim(Me.cboIncomeType1.Value & vbNullString) = vbNullString Then
    MsgBox prompt:="Please select Payment form.", buttons:=vbInformation, title:="SOFTWARE"
    Me.cboIncomeType1.SetFocus
    Exit Sub

    End If



    If IsNull(Me.OrderDateFrom) Then
    MsgBox "Please enter the Start date", vbInformation, "Date Range Required"
    Me.OrderDateFrom.SetFocus
    Else
    If IsNull(Me.OrderDateTo) Then
    MsgBox "Please enter the End date", vbInformation, "End Date Required"


    Me.OrderDateTo.SetFocus


    Else
    strCriteria = "[DATE] >= " & Format(Me.OrderDateFrom, "\#mm\/dd\/yyyy\#") & _
    " And [DATE] <= " & Format(Me.OrderDateTo, "\#mm\/dd\/yyyy\#") & _
    " And[PAYMENT_FORM] LIKE '" & IIf(IsNull(Me.cboIncomeType1), "*", Me.cboIncomeType1) & _
    " And[PAYMENT_MODE] LIKE '" & IIf(IsNull(Me.cboIncomeType), "*", Me.cboIncomeType) & "'"


    'task = "select * from PAY_FORM_ALL_EXPENSE where (" & strCriteria & ") order by [DATE]" ) #


    I initially thought my filter took effect but later realized the "DoCmd.ApplyFilter , strCriteria" was not applying the filter.

    Any help to fix this will be highly appreciated.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Note for future posts - please place code between CODE tags to retain indentation and readability.

    I have never used ApplyFilter method. Review this tutorial http://allenbrowne.com/ser-62.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,927
    Perhaps walk through your code line by line with F8?
    Add a Debug.print to make sure the criteria is correct including syntax?

    Code posted appears to be missing at least one End If ?
    Last edited by Welshgasman; 04-28-2022 at 03:57 AM.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    Emmanuel is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    272
    Quote Originally Posted by Welshgasman View Post
    Perhaps walk through you code line by line with F8?
    Add a Debug.print to make sure the criteria is correct including syntax?

    Code posted appears to be missing at least one End If ?
    Forget to add that
    There are two end ifs at the end of the code

  5. #5
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Code:
    Dim strCriteria, task As String
    This line declares strCriteria as a variant.
    Only "Task" is declared as a string (but never used).


    Code:
    strCriteria = "[DATE] >= .........."
    You have a field named "DATE"?
    Date is a reserved word in Access and shouldn't be used for an object name.
    Date is JET reserved (kb248738);ODBC (kb125948). Plus it is a built in function.
    Plus it is not very descriptive. "Date" of what??? Date Hired? Date fired? Date you got a loan? Date of payment?


    Also, should not use spaces or special characters/punctuation in object names.
    Last edited by ssanfu; 04-28-2022 at 08:11 PM.

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,927
    Quote Originally Posted by Emmanuel View Post
    Forget to add that
    There are two end ifs at the end of the code
    No good showing part of the code, especially when it does not even look like it can compile, as above.

    Examine the filter with debug.print and even walk through to make sure you even get to that line with Applyfilter on it.

    Here is an example of Apply filter direct from MS.

    Code:
     Private Sub tglFilter_Click()    With tglFilter
            If .Value = True Then
                .Caption = "P/T"
                .StatusBarText = "only full-timers"
                DoCmd.ApplyFilter , "[Hours]=40"
            ElseIf .Value = False Then
                .Caption = "All"
                .StatusBarText = "only part-timers"
                DoCmd.ApplyFilter , "[Hours]<40"
            Else
                .Caption = "F/T"
                .StatusBarText = "all employees"
                DoCmd.ShowAllRecords
                .SetFocus 'to activate the button's statusbar-text
            End If
        End With
    End Sub
    Found at https://docs.microsoft.com/en-us/off...md.applyfilter
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    Emmanuel is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    272
    This is a zipped copy of my database for analysis.
    thanks
    Attached Files Attached Files

  8. #8
    Emmanuel is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    272
    Kindly check in my codes and see which modifications can help fix the issue

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    There's a lot wrong. For starters, your form is in data entry mode so filtering it won't result in any records. Use this method:

    http://www.baldyweb.com/ImmediateWindow.htm

    To figure out the problems in your string. There are 3 if memory serves.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    Quote Originally Posted by June7 View Post
    Note for future posts - please place code between CODE tags to retain indentation and readability.
    That request has been made of Emmanuel before. Doesn't seem to be willing to accommodate.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  11. #11
    Emmanuel is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    272
    Quote Originally Posted by Micron View Post
    That request has been made of Emmanuel before. Doesn't seem to be willing to accommodate.
    Just not be able to figure out how is done. It doesn’t work when ever I try it

  12. #12
    Emmanuel is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    272
    Quote Originally Posted by pbaldy View Post
    There's a lot wrong. For starters, your form is in data entry mode so filtering it won't result in any records. Use this method:

    http://www.baldyweb.com/ImmediateWindow.htm

    To figure out the problems in your string. There are 3 if memory serves.
    So how do I go about it?

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Change the data entry property and then debug the criteria string as shown.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Quote Originally Posted by Emmanuel View Post
    Just not be able to figure out how is done. It doesn’t work when ever I try it
    Click the # icon on post editor toolbar. Type or copy/paste code between the CODE tags
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  15. #15
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,927
    Quote Originally Posted by Emmanuel View Post
    Just not be able to figure out how is done. It doesn’t work when ever I try it
    Code:
    The method is in my signature each time
    Then you will see what is generated, I tend to just type in the codes manually.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Page 1 of 3 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Me.Move not taking effect
    By GraeagleBill in forum Programming
    Replies: 4
    Last Post: 09-18-2021, 12:24 PM
  2. OrderBy specified in OnOpen event not taking effect
    By GraeagleBill in forum Reports
    Replies: 4
    Last Post: 03-21-2016, 11:53 AM
  3. Mouse-Over Button Effect Issue
    By McArthurGDM in forum Forms
    Replies: 4
    Last Post: 08-07-2014, 03:10 PM
  4. Shape Effect on Toggle Buttons
    By dimoc in forum Access
    Replies: 5
    Last Post: 04-10-2014, 09:28 AM
  5. Calculations Per Row Effect
    By gatsby in forum Access
    Replies: 29
    Last Post: 05-26-2013, 07:33 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums