Solved

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

Posted on 2014-03-25
3
667 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 35

Accepted Solution

by:
PatHartman earned 500 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 84
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can you open the FORM2 2 32
sql statement - 9 25
Cannot Link Master/Child Fields in a Navigation data sheet Sub Form 1 31
access query to sql server 3 21
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

809 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