Solved

Access Combobox SQL query not updating

Posted on 2016-09-21
5
35 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 34

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 34

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 34

Expert Comment

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

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now