Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Trying to limit the selection choices in 2nd combobox based on selectiong in 1st combobox

Posted on 2014-03-25
3
Medium Priority
?
701 Views
Last Modified: 2014-03-26
Main form - frmCustomers
Subform (shown in datasheet view) = subfrmPets

On the subform are two comboboxes.  I'm trying to limit the selections in the 2nd combobox (cboBreed), by the selection in the 1st combobox, (cboSpecies).

So in the rowsource for the 2nd combobox I have: (criteria in query designer)...

SELECT tblSpeciesBreeds.Breed, tblSpeciesBreeds.Species FROM tblSpeciesBreeds WHERE (((tblSpeciesBreeds.Species)=[Forms]![subfrmPets]![cboSpecies])) ORDER BY tblSpeciesBreeds.Breed;

But nothing is showing up.

What am I doing wrong?

--Steve
0
Comment
Question by:SteveL13
3 Comments
 

Author Comment

by:SteveL13
ID: 39953624
By the way, if I open the subform by itself in single form view the "filter" works fine.  It must be the way I'm referring (or not referring) to the form/subform.

??
0
 
LVL 40

Accepted Solution

by:
PatHartman earned 2000 total points
ID: 39954613
Two problems.
1. References to subform objects need to include the parent form -
Forms!mainform!subform.Form!yourcontrol
2. In the BeforeUpdate event of the first combo, you must requery the second combo.
Me.cboRight.Requery
0
 
LVL 85
ID: 39955629
<No points please>

When you refer to a Subform, you must refer to the SubForm CONTROL, and then refer to the Form property of that control:

[Forms]![subfrmPets].Form![cboSpecies]

If the Subform CONTROL on the parent form is named "subfrmPets" then this will work. If it's named something like "Subform1", this will fail.

Access defaults the name, depending on how you insert the Subform Control. If you drag the control from the designer toolbox, Access will name it something like "Contol1". If you drag a form and drop it onto another, Access will add a subform control, and will name it the same as the form you're using for a Subform.

BTW, your code works when the subform is opened directly because it's part of the Forms collection (ie. the "[Forms]!" part of the equation. When you use a form as a Subform, it's not part of the Forms collection, so you cannot refer to it using the "Forms!" syntax.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

971 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