Results 1 to 7 of 7
  1. #1
    vector39 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    May 2017
    Posts
    76

    List box no longer showing latest entry

    Hi Everyone


    So I have a list box based on a query with a number of records. My last issue was the list box not filtering based on either what the user types in or by date range. However I'm happy to say (thanks to Microsoft Community) that, now both search options work. However a new problem has occurred. A button that is used to open a form for the user to enter new information (new agency, address, insurance info, etc) did previously work as the new agency would appear in the list box but now when the user types in the new agency, nothing shows up at all. The updated SQL for the listbox (in design view) is as follows:

    Code:
    PARAMETERS Forms!frmMain!txtFrom DateTime, Forms!frmMain!txtTo DateTime, Forms!frmMain!SrchTxt Text ( 255 );
    SELECT tblAgency.AgencyName, tblSubsidiary.Subsidiary, tblAgency.AAEndDate, tblAgency.LiabilityInsurance, tblAgency.WSIBEmployeeDeclaration, tblAgency.Address, tblAgency.City, tblAgency.Province, tblAgency.PostalCode, tblAgency.ContactName, tblAgency.ContactEmail, tblAgency.ContactPhoneNumber, tblPrograms.Program
    FROM tblPrograms INNER JOIN (tblSubsidiary INNER JOIN tblAgency ON tblSubsidiary.ID = tblAgency.[Subsidiary].Value) ON tblPrograms.ID = tblAgency.Programs.Value
    WHERE (tblAgency.AAEndDate Between Forms!frmMain!txtFrom And Forms!frmMain!txtTo 
    OR tblAgency.LiabilityInsurance Between forms!frmMain!txtFrom AND Forms!frmMain!txtTo) 
    AND tblAgency.AgencyName & tblSubsidiary.Subsidiary LIKE "*" & Forms!frmMain!SrchTxt & "*"
    ORDER BY tblAgency.AgencyName;

    I have also tried adding this bit of code to button’s on click procedure which is:

    Code:
    DoCmd.OpenForm "frmAddNewAgency", DataMode:=acFormAdd, WindowMode:=acDialog
    Me.SearchResults.Requery
    When the button is clicked it opens the add new agency form (frmAddNewAgency), the user is able to enter the new information, hit save and then close, but nothing simply happens. The new info is not visible in the list box but appears in the agency table. If anyone has any guidance on how to tackle this issue. That would be much appreciated!

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    you need to requery the listbox after changing the underlying data

  3. #3
    vector39 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    May 2017
    Posts
    76
    Quote Originally Posted by Ajax View Post
    you need to requery the listbox after changing the underlying data
    So would something like:

    Code:
    Me.SearchResults.Requery
    be included in the AfterUpdate or AfterInsert event procedure?

  4. #4
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    Since this is a select query, it has no direct effect on your table (I'm saying it's not directly responsible for updating your table). Which leads me to ask-
    if you paste this sql into a new query, and the form is open and the necessary fields have data, does it actually work? You have a bunch of AND / OR operators all grouped into one set of parentheses, which could be interpreted much differently than you expect. Your post reads as if the sql statement has been updated, now it doesn't work. I'd try it in a new query and see if Access highlights any problems. If you get no records, it's usually easier to trouble shoot it there.

    It is also possible that your sql could be a whole lot simpler. Perhaps you have the record id (autonumber or whatever) hidden on the form, in which could shorten things, assuming the id is common to any other table involved (it is a foreign key).
    Last edited by Micron; 06-08-2017 at 07:47 AM. Reason: added info
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    vector39 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    May 2017
    Posts
    76
    Hey guys

    So I deleted the previous button, made a new form based on the agency table and added a new button. And now the new entry appears on the list box. So the simple solution here was to delete and add a new button. Even though this problem is now technically solved, I'm still open to suggestions about list boxes and requerying in general. Thank you all so much!

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    depends on how your form and listbox is intended to work


    the listbox is always requeried when the form is opened

    you can set code to requery it after any event where you know or think the data might change - could be

    the form current event (user has selected a new record)
    the listbox afterupdate event (user has selected a different option) - so perhaps the option needs to be removed from the list so it can't be selected again.
    the listbox enter event (the user has changed something somewhere else on the form which affects what should be listed) - alternatively the after update event of the control which changed which affects the values to be listed (typically what are called cascading combo's) and depends on when you want the changed values to be visible - in your case perhaps the click event on your button
    and for combo's, not listboxes - the 'on not in list' event - user has added a new value

    but don't go requerying all the time, only when necessary, otherwise your form will slow down with constant interrogation of the tables.

  7. #7
    vector39 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    May 2017
    Posts
    76
    Thank you!

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

Similar Threads

  1. Data entry form no longer works
    By Jamesiv1 in forum Access
    Replies: 1
    Last Post: 05-13-2014, 09:18 PM
  2. Replies: 5
    Last Post: 03-09-2014, 07:16 PM
  3. Replies: 4
    Last Post: 07-04-2013, 12:07 PM
  4. Replies: 6
    Last Post: 08-24-2012, 12:04 PM
  5. Capturing Latest Entry on Subform
    By Marie1106 in forum Forms
    Replies: 3
    Last Post: 02-21-2012, 10:40 AM

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