List box no longer shows newest entry (1 Viewer)

vent

Registered User.
Local time
Today, 00:49
Joined
May 5, 2017
Messages
160
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:
[B]PARAMETERS[/B] Forms!frmMain!txtFrom DateTime, Forms!frmMain!txtTo DateTime, Forms!frmMain!SrchTxt Text ( 255 );
[B]SELECT[/B] 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
[B]FROM[/B] tblPrograms INNER JOIN (tblSubsidiary INNER JOIN tblAgency ON tblSubsidiary.ID = tblAgency.[Subsidiary].Value) ON tblPrograms.ID = tblAgency.Programs.Value
[B]WHERE[/B] (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 & "*"
[B]ORDER BY[/B] 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!
 

BigHappyDaddy

Coding Monkey Wanna-Be
Local time
Yesterday, 21:49
Joined
Aug 22, 2012
Messages
205
Sounds like you need to requery the listbox recordsource after the new agency record has been saved.

Sent from my SM-G900P using Tapatalk
 

vent

Registered User.
Local time
Today, 00:49
Joined
May 5, 2017
Messages
160
Sounds like you need to requery the listbox recordsource after the new agency record has been saved.

Do you mean something like this:

Code:
Me.SearchResults.Requery

Be applied to AfterUpdate or AfterInsert event procedure?
 

BigHappyDaddy

Coding Monkey Wanna-Be
Local time
Yesterday, 21:49
Joined
Aug 22, 2012
Messages
205
If SearchResults is the name of your listbox, then I do believe that is the correct syntax. As for where to put it, I think you are referring to form frmAddNewAgency's AfterUpdate event. Should work, but I don't know the rest of your solution to know if it "fits" there.

Sent from my SM-G900P using Tapatalk
 

vent

Registered User.
Local time
Today, 00:49
Joined
May 5, 2017
Messages
160
If SearchResults is the name of your listbox, then I do believe that is the correct syntax. As for where to put it, I think you are referring to form frmAddNewAgency's AfterUpdate event. Should work, but I don't know the rest of your solution to know if it "fits" there.

Yes, SearchResults is the list box name. I tried putting:

Code:
Me.SearchResults.Requery

Into fromAddNewAgency's AfterUpdate event, but I get an error saying

Compile Error:
Method or data not found


With SearchResults being highlighted. I assume this is because SearchResults is not on this form, but on another form called frmMain
 

BigHappyDaddy

Coding Monkey Wanna-Be
Local time
Yesterday, 21:49
Joined
Aug 22, 2012
Messages
205
Replace "SearchResults" with the name of your ListBox.
Code:
Me.ListBoxName.Requery
But your error makes me think that this solution is not quite complete. I believe your listbox is on frmMain, but you want to update the listbox AFTER the new record in frmAddNewAgency is saved.
You might have to explicitly reference frmMain in the AfterUpdate event of form frmAddNewAgency. So try something like this:

Code:
Forms!frmMain.ListBoxName.Requery
 
Last edited:

vent

Registered User.
Local time
Today, 00:49
Joined
May 5, 2017
Messages
160
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!
 

Users who are viewing this thread

Top Bottom