Results 1 to 7 of 7
  1. #1
    Ganymede is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Dec 2011
    Posts
    116

    Applying string criteria to Where statement


    I have a form with a listbox titled "CostReportAppealsWindow." When the form loads, I want to populate the listbox with data from a query titled "CostReportAppealsSplashQ". In doing so, I want to apply a filter to a field titled "Status," which can have one of four values: "Pending Paralegal Review, "Pending Associate Review", "Pending Partner Review" or "Complete". On form load, I want to filter out the "Complete" files. (I intend to make a toggle button to make the completes viewable after I figure out the Where statement logic.)

    Here's the code that I built to acheive the desired outcome.
    Code:
    Private Sub Form_Load()Me.CostReportAppealsWindow.RowSource = ""
    Dim strSource As String
    Dim rc As String
    rc = "Review Complete"
    strSource = "SELECT  CostReportAppealID, [Appeal Deadline], CCN, [Hospital Name], FYE, [Issue Name], [Client Name], [Designated Paralegal], [Designated Attorney], [Status]   " & _
    "FROM [CostReportAppealsSplashQ]" & _
    "Where [Status] <> '*" & rc & "*' "
    Me.CostReportAppealsWindow.RowSource = strSource
    End Sub
    The listbox populates just fine, but it does not apply the filter. "Review Complete" files appear in the listbox. Do I need to change the Where logic? I thought I was following the standard procedure for string query criteria. I researched this for a bit but couldn't find quite what I'm looking for. Any guidance would be greatly appreciated.

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,927
    Debug print strsource - you’ll find your are missing a space before WHERE and have an extra one after *’

    other issues - when using wild cards, you use like or not like rather than = or <>

    And since you have the exact phrase to exclude, you shouldn’t need wild cards

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,550
    and have an extra one after *’
    That is not going to matter, surely?

    Why people never check what they construct is beyond me.
    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
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,927
    That is not going to matter, surely?

    so you think ‘abc’ =‘abc ‘?

    other issue is the OP says the value in the field is ‘complete’ but they are trying to exclude ‘review complete’. I presume that is a typo

  5. #5
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,818
    Excuse my lack of knowledge but if the Listbox is based on a query why does the OP need VB in the Forms ON Load?
    Surely he can apply the filter in the query?

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,550
    Quote Originally Posted by CJ_London View Post
    so you think ‘abc’ =‘abc ‘?

    other issue is the OP says the value in the field is ‘complete’ but they are trying to exclude ‘review complete’. I presume that is a typo
    Code:
    rc = "Fred"
    ? "Where [Status] <> '*" & rc & "*' "
    Where [Status] <> '*Fred*'
    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
    Ganymede is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Dec 2011
    Posts
    116
    Quote Originally Posted by CJ_London View Post
    Debug print strsource - you’ll find your are missing a space before WHERE and have an extra one after *’

    other issues - when using wild cards, you use like or not like rather than = or <>

    And since you have the exact phrase to exclude, you shouldn’t need wild cards
    Thank you so much. Getting rid of the wildcard did the trick. Marking as resolved.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 06-02-2025, 04:15 AM
  2. applying criteria to 2 fields in different tables
    By dawnnolan54 in forum Queries
    Replies: 6
    Last Post: 09-02-2015, 04:01 PM
  3. Replies: 4
    Last Post: 04-22-2013, 06:45 AM
  4. Apply Filter 2 criteria not applying
    By ahightower in forum Forms
    Replies: 4
    Last Post: 07-28-2011, 03:31 PM
  5. Replies: 2
    Last Post: 05-09-2011, 06:45 PM

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