[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Access Combobox SQL query not updating

Posted on 2016-09-21
5
Medium Priority
?
187 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 39

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 39

Accepted Solution

by:
PatHartman earned 2000 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 39

Expert Comment

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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

650 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