Loading Data on a subform based on Combo Box value

G

Guest

Hello all, I would really appreciate if someone can help me with it. I know
it's simple. But I just can't get it. I tried for hours before I gave up. All
I want is to display values in a subform based upon the value user chooses in
a combo box. I have three fields to be displayed "Parts", "Vendors", "Cost"
from a table called "Directory" and my combo box value is also from this
table but it has only the distinct values for "Parts". So what I want is
whenever the user chooses a "Part" in the combo box, the subform should
display all records with the chosen part value and it's corresponding Vendor
and Cost values. I have my combo box now with the distinct Parts based upon a
query and that query is the source for my form. I have another table which
has all the three fields as the source for my subform. But it's not working.
It pulls the data when the form gets loaded correctly for the first Part
type. But when I change my combo box value, the subform doesn't reflect it.
And I tried using after update for my combo box and I have given it's coding
below:
Private Sub cmbPartType_AfterUpdate()
DoCmd.OpenQuery "query1"
End Sub
Please let me know where I am going wrong.
Thanks!
 
A

Allen Browne

I take it your main form is unbound, and has a combo for selecting the
PartID. You then want the subform to show records for this part.

You can do that without code. In form design view, right-click the edge of
the subform control, and choose Properties. Set the LinkChildFields property
to the name of the field in the subform (e.g. PartID.) Set the
LinkMasterFields property to the name of the combo in the main form.

This assumes the combo is set up correctly so its Bound Column matches the
PartID field in the subform. The subform can be based on the table (i.e. it
doesn't need a query to filter it.)
 
G

Guest

Thanks, Allen. It's working except for that the subform displays only two
fields and it's not displaying the "Part Type" field. Any idea why it's not
working?

I am appreciate your help again!

Thanks!
 

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