Link to home
Start Free TrialLog in
Avatar of culpees
culpeesFlag for United States of America

asked on

Unbound form control won't requery/refresh

I have been working for an entire day at getting a single unbound control to requery. Refresh. whatever.

A single form.
2 combo boxes.
1 is populated and woolah!
The second one is filtered to the results limited by the 1st combo box's selection.

I've done this type of reference a hundred times but this time I can't get the darn combo box #2 to actually requery itself to the results of the newly changed combo box #1. Both are unbound. Both are on the same form. Both are enabled, visible, unlocked.

Funny, the sql query on the rowsource for combo box #2 works great. The combo box doesn't.

I've tried access macros using actions:
runcommand with refresh, runcommand with run or just fun ol' macro action requery.

I've tried using different vba options:
docmd.requery
me.cmbSPASelect.Requery
[Forms]![MAIN]![cmbSPASelect].Requery

I've tried putting the macros/vba on the after update event of combo #1.
As well as the on enter event, on got focus event, on click event for combo #2.

Problem with the on enter and on got focus events is that, combo #1's action can't set the focus to combo #2 when I use those. So I'm stuck with on click but I can't get it to work.

Please help me. This is my mountain. I must get over it!
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

"The second one is filtered to the results limited by the 1st combo box's selection."
What is the Row Source SQL for the 2nd combo
What are the names of the Combo boxes?

You have a couple of options
1. After Update event of Combo 1

Private Sub Comb1_AfterUpdate()
    Me.Combo1.Requery
End Sub

2.  On Enter event of Combo 2

Private Sub Combo2_Enter()
    Me.Combo2.Requery
End Sub

If neither of these work, then something unusual is going on, like the Row Source for Combo2 is not correct.

mx
Avatar of culpees

ASKER

I read this article. I'm keeping it for prosperity. But I don't see how my exact scenario fits in.

I could apply the row souce using cases in vba BUT if we apply more options to the table, then I'd have to manually adjust the vba as well to include the additional case options. This is out of the question.

The row source is defined already and works outside the combo. It actually works in the combo the first time you activate the form. But then once you click on it after updating the combo1 it doesn't reflect the change seen in combo1.

And, bonus.
Combo 2 needs to remain UNFILTERED at all if combo 1 is blank. so my query is seen below:
SELECT PEI_SPA_CODES.NAME_SHORT, PEI_SPA_CODES.NAME, PEI_SPA_CODES.TEAM FROM PEI_SPA_CODES WHERE (((PEI_SPA_CODES.TEAM) Like "*" & [forms]![MAIN]![cmbTeam] & "*")) ORDER BY PEI_SPA_CODES.NAME;

So if combo1 is null, the query returns all records. If combo 1 has a selection, it limits the records.

Why if the query works won't the combo requery?
Avatar of culpees

ASKER

wow. good timing mx.

combo 1 = cmbTeam
combo 2 = cmbSPASelect

on option 1 you posted:
did you mean literally to requery combo1? not combo2?
typo sorry

Private Sub Comb1_AfterUpdate()
    Me.Combo2.Requery
End Sub
Avatar of culpees

ASKER

okay. well I tried both. Those were initial efforts too actually. No go.

What's next? Please tell me there's more???
Can you upload the db ... or a one that exhibits the issue ?

mx
Avatar of culpees

ASKER

Sure thing!

I made a substitute database which is seen attached here. It has the applicable form, tables, macros and queries in it.

It is stripped of proprietary data but there is enough there to test it and see what it is doing. I was able to replicate the problem with this copy.

Steps:
Option 1. Team Rep ("combo 2") needs to be unfiltered. Click on Team Rep to get a full list. (IF the Team Rep has a profile set up as indicated by fields in the underlying table for that control, that selection will then populate the 3 boxes to the right including "combo 1" (Team).)

Option 2. Team Rep ("combo 2") needs to be filtered based on Team ("combo 1") selection.

So basically an "if". If [Team] has a selection in it, then limit "Team Rep", else no limitation.

((You'll get a "REGISTRY" form error when opening the main form. It's because that form is a subform which is not included in this database since it's not affected by my immediate problemo.))

Thank you so much for looking at this!!!!!
db4.mdb
the db/txt file is zero bytes ...!

mx
Avatar of culpees

ASKER

Okay. this time it took it. I don't know what happened.
db4.mdb
Ok ... can you tell me the exact steps ....with current results and expected results.  IE ... do this, then that ... specifying what values to select ... and what should be the results.

thx.mx
Avatar of culpees

ASKER

1 of 2 things should happen.

1:
(Team is null and not populated.)
Click Team Rep and see a full list, unlimited. This is good.
Make a selection (example, SP or GG). If user has a profile set up, then you'll see the 3 fields to the right populate. (The Team populates for all users though the Area and Asset may not be set up for everyone's profile yet.)

So in short. The Team Rep selection from an unrestricted list will populate the Team as well as the Area and Asset.

OR

2.
Let's say Team is populated now, due to a previous search. This is good.
I want to go backwards now.
Click Team Rep, and now this list should be restricted by the Team selection (only because the Team is not null and actually has a value in it.)

# 2 is the part I can't get working. I want to be able to click the Team and then go to the Team Rep and see that list become limited to whatever is selected in Team if it has something selected. Otherwise the Team Rep needs to remain a full, unlimited list if Team is empty.
Avatar of culpees

ASKER

Currently, for part 2... Team will have a value in it and I click Team Rep to see the limited list but it's not filtering. The Team Rep filter will work 1 time once you activate the form. After that, you can change the Team and then go to the Team Rep and see no change in the list even after the Team has been changed.

Sorry, forgot to mention what it is currently doing.
"Currently, for part 2... Team will have a value in it and I click Team Rep to see the limited list but it's not filtering."

Seems to me that is is filtering - see images.

What am I missing ?
Capture1.gif
Capture2.gif
Capture3.gif
In Afterupdate event for field cmbTeam, add requery for field cmb.SPASelect

Private Sub cmbTeam_AfterUpdate()
    Me.cmbSPASelect.Requery
   
ASKER CERTIFIED SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
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 culpees

ASKER

MX,

I can see that you switched the code in the after update on combo1. I swear I had that before and it didn't work then! I'm glad it's working now. It appears to be doing exactly what I want it to do now. So I've replicated it to my actual db and we're good to go.

I am so pleased. Thank you for helping me last night. That was fantastic.

You are very welcome.
Thank you for using Experts Exchange.

mx