Solved

Access Combobox SQL query not updating

Posted on 2016-09-21
5
86 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
  • 3
  • 2
5 Comments
 
LVL 36

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 36

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 36

Expert Comment

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

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

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…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

696 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