Combo Box (One to Many Relationship)

Martano0811

Registered User.
Local time
Today, 00:14
Joined
May 14, 2012
Messages
16
I have a combo Box in a split form and would like the form to filter only on specific critera. For Example, there is one to many relationship to "Region" in my data and would only like to show all records in the "West" region. Currently when I use the combo box on a specific region it just moves to the next region in the form but includes all regions. I would like to show only the specific region (West, East, Central) Any assistance would be nice. (Im only using one table in this example)
 
Last edited:
There are at least two ways to do this - the Access way and the client/server way. I always choose the client/server way because it works in all cases.

Change the form so that its RecordSource query references the unbound combo where you are choosing the Region.

Code:
Select ....
From ...
Where Region = '" & Forms!yourform!cboyourregion & "'";
or, if you want to allow all
Code:
Select ....
From ...
Where Region = '" & Forms!yourform!cboyourregion & "'" Or Forms!yourform!cboyourregion Is Null;

Then in the AfterUpdate event of the region combo put:
Code:
Me.Requery
 
This helps:

Im getting Error on this in the Record Source query...is there something wrong with the syntax?


SELECT [CPC Weekly Data].Region
FROM [CPC Weekly Data]
Where [CPC Weekly Data].Region = ' " & Forms!CPCREMilestoneFormReport!CboRegion & "'"
GROUP BY [CPC Weekly Data].Region
ORDER BY [CPC Weekly Data].Region;
 
What is the error message?

Is the region a text field or is it numeric? If it is numeric, it should not be enclosed in quotes.
 
Yes, it is Text, "error message in string in query expression": Where [CPC Weekly Data].[Region] = ' " & Forms!CPCREMilestoneFormReport!CboRegion & "'"
 
Last edited:
Where [CPC Weekly Data].Region = Forms!CPCREMilestoneFormReport!CboRegion

You only need the quotes and the ampersands if you are building a SQL string in code. If this SQL is in the RecordSource, replace it with the above syntax.
 
Great thank you Pat, one last thing a prompt is coming up ...."Enter Parameter Value" ....this shouldnt happen should it?
 
Access is prompting for a parameter because whatever it is is misspelled. Or, if it is asking for the form field, it may be that the form is not open. A form must be open for it to be referenced from a query or other form/report/code.
 

Users who are viewing this thread

Back
Top Bottom