?
Solved

Requery combo box as soon as it's selected

Posted on 2014-12-27
11
Medium Priority
?
194 Views
Last Modified: 2014-12-29
I have a combo box that has a saved query as its row source. The query has as a "where" clause that is based on a field of the currently selected row. That means that when the user selects the combo box, before displaying the drop down list, the I need to requery the combo box so the correct selection criteria is used to generate the list.

I found I can do this by using the GotFocus event but that makes selection very jerky - the combo box is selected, the drop down list appears and then closes then on the second click. Is there another way I can accomplish what I need?
0
Comment
Question by:Rob4077
[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
  • 6
  • 2
  • 2
  • +1
11 Comments
 
LVL 24

Accepted Solution

by:
Eirman earned 2000 total points
ID: 40519596
You could try the Form's OnCurrent event and see how that compares
0
 
LVL 24

Expert Comment

by:Eirman
ID: 40519604
Another thought  ..... Try putting

me.comboboxname.requery
in the afterupdate event of the txtbox of the field in question.
0
 

Author Comment

by:Rob4077
ID: 40519606
That seems to work but I can't do a me.activecontrol.requery because it tells me it requires the control to be in the active window. That means I have to wither list all 7 combo boxes that need to be requeried in the OnCurrent event or I need to run a Select Case to determine which control has been selected and then requery that one. It would work but is there another solution?
0
Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

 

Author Comment

by:Rob4077
ID: 40519609
Actually I can't build the Select Case statement because the me.ActiveControl.name won't work so my only alternative is to requery all 7 combo boxes each time the OnCurrent event is triggered. I think this adds an unnecessary load if I can avoid it
0
 

Author Comment

by:Rob4077
ID: 40519612
You also said try putting "me.comboboxname.requery  in the afterupdate event of the txtbox of the field in question" What do you mean by "the txtbox of the field in question"? No fields are updated until the user selects something from the combo box. That combo box should list options based on another field in the selected record.
0
 
LVL 58
ID: 40519647
You don't want to requery in OnCurrent.

Instead, what Eirman was suggestion is to use the afterupdate of the controls that are used as part of the combo's where clause.

Jim.
0
 

Author Comment

by:Rob4077
ID: 40520082
That would work if I had to change a control before using the combo box but that doesn't need to happen. The user can simply open the form, go straight to the combo box and try to make a selection. The query needs to refresh before they make the selection. Let me explain a little further.

The form lists each supplier and allows the user to assign an activity to each using a combo Box. When you click the combo box I want it to list only those Activities that this supplier is capable of doing so the rowsource of the combo box uses a saved query that lists suitable jobs
(WHERE tblSupplierActivities.fkSupplierId=[Forms]![frmWeekViewHolder]![sfrmWeekView].[Form]![Supplierid]).

The trouble is that if I choose say the 3rd row in the form, the combo box does not use the currently selected row as qualifier because the query hasn't refreshed. I can click on any row in the form but it keeps using the same criteria unless I press F5 to requery the control first, then it will list the correct Activities
0
 
LVL 85
ID: 40520406
Does the Supplier change when you move to a different row in that form? If so, then you could use the Current event of the Form and set the RowSource of that combo directly. Assuming the combo resides on the subform, then you could do this:

Me.YourCombo.RowSource = "SELECT * tblSupplierActivities WHERE fkSupplierID=" & Me.SupplierID
0
 

Author Comment

by:Rob4077
ID: 40521036
Yes, the supplier changes each row.

Your suggestion to use the OnCurrent event is the same as Eirman's solution. I have implemented it and it works but I haven't closed out the question because I have to requery 6 combo boxes in the OnCurrent event and I was hoping there would  be another way. Besides, this doesn't seem to be universally recommended - Jim said "You don't want to requery in OnCurrent".

I have searched through EE for similar questions and it looks like I am the only one who has raised this issue.
0
 
LVL 58
ID: 40521623
<< Jim said "You don't want to requery in OnCurrent". >>

  I was assuming a different situation.  In this case, you don't have any other choice.

Jim.
0
 

Author Comment

by:Rob4077
ID: 40523163
Thanks for the clarification Jim. As I said it works with this approach so Eirman gets the points since he is the one who suggested in first. Thanks to others for your input
0

Featured Post

Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
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…
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: …
Suggested Courses

764 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