list box focus? question

P

Piperlynne

Ok, I have two drop down boxes. cboCustomer and cboBrand
Customer selects from the tblCustomer and Brand selects from tblBrand based
on what CustomerName is selected in cboCustomer.
I then have a list box that displays all projects (Project table) based on
BrandName.
Then I have a subform that based on what is selected in the list box (Project)
displays the project details based on projectID matching.
Everything works like it should HOWEVER.
When I drop down customer, then brand. I have to click on the list box to
get the values. And when I select a project, I have to click into the subform
to get it to refresh.
Is there a way to make it so when you select the brand, the project list box
populates and displays without having to click it. And when you click on a
project in the list box, the subform displays the selection without clicking
into it?
 
A

Arvin Meyer MVP

Yes, in the AfterUpdate event of the control you start with, use it to
requery the other control(s). Example (aircode):

Sub cboCustomer_AfterUpdate()
Me.cboBrand.Requery
Me.SubFormName.Form.cboControlName.Requery
End Sub
 
G

ghetto_banjo

perhaps on the afterupdate event of the cboBrand, run the code:

me.listboxName.requery
me.subFormName.requery
 
P

Piperlynne

Thanks!!
Ok, I got that to work - for the list box. And it works after a fashion on
the subform. But for some reason, I have to click the subform, then click on
the list box in the main form to get the selection in the subform to change.
 
A

Arvin Meyer MVP

Probably because there is more than a single record in the subform. If your
subform is in single form view, the code should work fine without having to
click on a specific record.
 
A

Arvin Meyer MVP

ghetto_banjo said:
perhaps on the afterupdate event of the cboBrand, run the code:

me.subFormName.requery

Not quite. A subform is a control on the form which has a form property that
must be addressed if the subform does not have the focus. From within the
form or subform

Me.Requery

is correct, but when referring to the subform from the main form the syntax
is:

Me.SubformControlName.Form.Requery
 
P

Piperlynne

Yes, there are multiple records in the subform.
I want to be able to click on the list box in the main form and have it
change the record selected in the subform. And it does that. But I have to
click on the subform, then go back and click on the listbox in the main form
to get it to change.
Is there a way to get the subform record to change without having to click
in the subform, then go back and click the list box?
It seems like a focus issue. Like it doesn't understand that I want it to
change the record in the subform until I click on it. (LOL, I'm talking like
its a human)
 
A

Arvin Meyer MVP

I suggest making you selection in the listbox first, then use an event,
perhaps the double-click event of a textbox or GotFocus event in a combo box
to requery.

The syntax for working with the listbox on the main form is:

Me.Parent.ControlName
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top