Results 1 to 4 of 4
  1. #1
    skydivetom is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    1,038

    VBA -- "Requery" control does NOT appear to work as envisioned

    Good morning:



    I have a fundamental question about "requery" on a form. Apparently, the "REQUERY" does not give me the expected results. I'm sure the answer is staring me right in my face, but seems like I need a 2nd set of eyes to figure out the answer.

    Attached is a DB containing a search form/DB with 50 sample records. Allow me to provide some background first.

    Background:
    - Upon opening the DB, the search form opens by default.
    - In the top left, I have a list box that displays all available jobs. Once I click on any of these, the large listbox (bottom) is updated accordingly.
    - In addition to the listbox "Search by Job Title", I also have an unbound textbox "Search by Keyword"... in yellow (top right).
    - If I were to type, e.g., "snake" (I randomly generated 50 keywords), the large listbox at the bottom is filtered and now shows 3 jobs matching the keyword criteria.

    ... so far so good... no changes are required up until this point.

    Existing process:
    1. If I select "Business Analyst (7)", 7 jobs are displayed.
    2. If I select any other job, the listbox gets updated accordingly.
    3. Just like #2, the large (results) listbox also gets updated when I type into the yellow texbox any existing keyword (i.e., randomly selected animal in this case).

    Underlying issue:
    - If I chose a value from the listbox but then want to display ALL RECORDS (50) records again, I currently have to type any characters (e.g., XYZ) AND THEN "backspace" on my keyboard to show all 50 records.
    - To prevent the need for having to type any characters into the yellow unbound textbox AND then having to BACKSPACE (on my keyboard), I added an option to my "Actions" listbox ("Clear Search Criteria").

    The associated VBA for clicking this item is as follows:

    Code:
        'Clear Search Criteria (listbox and combo)
        If Me.lstActions = "Clear Search Criteria" Then
            txtSearch.Value = Null
            lstSearch.Value = Null
            Me.lstBox.Requery
        End I
    So, while the command "txtSearch.Value = Null" removes any values (ultimately, the same as the manual BACKSPACE), the line "Me.lstBox.Requery" does NOT requery/refresh the large listbox and show all 50 records again.

    Why is that? Is there another command that I need to use to requery/refresh control "lstBox"?

    I'd welcome any suggestions/recommendations to solve this small issue. Thank you!

    Cheers,
    EEH
    Attached Files Attached Files

  2. #2
    skydivetom is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    1,038
    Update to post #1:

    - I forgot to mention, there's also a hidden (orange) unbound textbox "txtSearch2" on the form.
    - This is the control that stores the keyword (from either lstSearch OR txtSearch).

    I modified the VBA and included the updated DB (with the control unhidden). Updated VBA is as follows:

    Code:
        'Clear Search Criteria (listbox and combo)
        If Me.lstActions = "Clear Search Criteria" Then
            txtSearch.Value = Null
            txtSearch2.Value = Null
            lstSearch.Value = Null
            Me.txtCountListbox.Value = Me.lstBox.ListCount
        End I
    Unfortunately, the outcome hasn't changed... the large listbox still does NOT show all 50 records even when control txtSearch2 is set to null.

    Question remains: Why doesn't the requery work as envisioned?
    Attached Files Attached Files

  3. #3
    skydivetom is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    1,038
    Found the issue... sorry, I had been looking at this for too long:

    Code:
        If Me.lstActions = "Clear Search Criteria" Then
            txtSearch.Value = Null
            txtSearch2.Value = Null
            lstSearch.Value = Null
            
            Me.lstBox.Requery
    
    
            Me.txtCountListbox.Value = Me.lstBox.ListCount
        
        End If

  4. #4
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    Talking to yourself or trying to explain an issue to someone else often makes the lightbulb come on
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

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

Similar Threads

  1. Suppress "Requery" and/or "Repaint" when running function
    By GraeagleBill in forum Programming
    Replies: 3
    Last Post: 12-08-2017, 12:04 AM
  2. Replies: 12
    Last Post: 12-21-2016, 04:27 AM
  3. Replies: 1
    Last Post: 09-07-2015, 08:00 AM
  4. Replies: 7
    Last Post: 12-21-2014, 08:21 PM
  5. Replies: 2
    Last Post: 09-29-2012, 11:22 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