Link to home
Start Free TrialLog in
Avatar of Nige JK
Nige JK

asked on

Access Combobox SQL query not updating

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
Avatar of PatHartman
PatHartman
Flag of United States of America image

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.
Avatar of Nige JK
Nige JK

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of PatHartman
PatHartman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Nige JK

ASKER

Works fine now thanks.
You're welcome.  Don't forget to close the question.