Solved

Access Combobox SQL query not updating

Posted on 2016-09-21
5
103 Views
Last Modified: 2016-09-22
In a child form I have a combobox which runs a SQL query on a linked table (containing contacts) to allow me to choose a record.

If I update the linked table with another contact and then use the combobox its query does not find the new contact. The contact table is updated.

I can manually make this work by doing a shift+F9 refresh when the combobox is active. I want to make this refresh automatic. I have tried inserting Me.Refresh and Me.Requery code behind the click event for the combobox.

What is the code for the manual  shift+F9 and where should it go to make it work?

Cheers
0
Comment
Question by:Nige JK
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 38

Expert Comment

by:PatHartman
ID: 41809041
When a form opens, the recordsource and any rowsources for listboxes and combos are populated.  The recordsets are refreshed periodically and will "see" updates and deletes but will not "see" additions.  To see additions, you must use the .Requery method.

If the Rowsource is being updated using a form, you can have the AfterUpdate event of that form check to see if a particular other form is open and if it is, then requery the combobox in question but this only works if the same user is updating the RowSource as using it.  If some other user adds a new item to the RowSource table, it will not be reflected in the RowSource of any form opened by a different user.
0
 

Author Comment

by:Nige JK
ID: 41809370
Thanks Pat. I have made it work using the requery on got focus event of the combobox. It does require to focus on a different item eg textbox and then back onto the combobox to trigger it.

There is an alternative method I want to try but am having trouble specifying the combobox in the location I am running the code.

 I update the contacts in a form. On that form I have a 'Save' button that triggers a refresh on clickk event but I am thinking I could put the combo requery in that event as well. However I cant seem to make it find the combobox. The combobox is called 'StructuralEngineer' and is in a form called 'FormSE' which is a child form in the main form 'Switchboard'  

What is the correct syntax?

Thanks
0
 
LVL 38

Accepted Solution

by:
PatHartman earned 500 total points
ID: 41809428
When referencing the combo from a different form:

Forms!formname!cboName.Requery

If the combo is in a subform:

Forms!mainformname!subformname.Form!cboName.Requery

When referencing the subformname in this context, use the name of the subform CONTROL, which might be different from the name of the actual subform object.
0
 

Author Comment

by:Nige JK
ID: 41810252
Works fine now thanks.
0
 
LVL 38

Expert Comment

by:PatHartman
ID: 41810765
You're welcome.  Don't forget to close the question.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question