?
Solved

Filter query from access form using variable

Posted on 2012-12-31
5
Medium Priority
?
393 Views
Last Modified: 2012-12-31
I would like to limit the output of a query based on the value of a variable on an acces form.

I am sure the answer is simple but the syntax i don't know.

The original query is named qry_PDM_Measures and includes...

- Project Category
- Measure

The combo boxes i want to control are on a form named frm_PDM_Results.....

cboProjectCategory
cboMeasure

When a value is selected from cboProjectCategory i want to limit the list in cboMeasure to those measures where Me.ProjectCategory on the form is equal to Project Category in the query.

Any help most welcome.

Thank you.
0
Comment
Question by:SweetingA
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 48

Accepted Solution

by:
Dale Fye earned 2000 total points
ID: 38733551
This is called cascading combo boxes.  In order to make this work, you must have a table where you have both sets of values.  You need to set the RowSource for the 2nd combo to:

SELECT DISTINCT Measure
FROM qry_PDM_Measures
WHERE [Project Category] = Forms!frm_PDM_Results.cboProjectCategory

You then need to add code two two events, the first is to the cboProjectCategory_AfterUpdate event.  it should look like:

Private Sub cbo_ProjectCategory_AfterUpdate

    me.cboMeasure.Requery

End Sub

The other is in the Form_Current event.  This will make sure that if you go to a record that already has values in those fields, the combo box will display the correct list of items for the already selected Project Category

Private Sub Form_Current

    me.cboMeasure.Requery

End Sub
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38733586
SweetingA ,

Hey, I have not heard from you in a while.

Nice of you to post on the last day of the year...
;-)

Anyway, here are some popular links to investigate as well:
http://fontstuff.com/access/acctut10.htm
http://www.candace-tripp.net/download/CascadeCombo2007.zip
http://www.candace-tripp.net/download/cascadecombo2k.zip
http://www.candace-tripp.net/download/2table_cascadecombo2k.zip

JeffCoachman
0
 

Author Comment

by:SweetingA
ID: 38733708
Hello Jeff,

I am not an access programmer as you may have gathered, i am just a person that likes to dabble for fun now and again but i do like to see who is doing well in the league table.

Regards
0
 

Author Comment

by:SweetingA
ID: 38733715
Hello Fyed,

The result earns the points thats for sure but can you just add one tiny extra bit to the criteria

....And WHERE [Measure] <> Forms!frm_PDM_Results.cboProjectCategory....

or something similar

Regards
0
 

Author Comment

by:SweetingA
ID: 38733730
Solved, just a couple of bracket problems

WHERE (([Project Category] = Forms!frm_PDM_Results.cboProjectCategory) And ([Measure] <> Forms!frm_PDM_Results.cboProjectCategory))

Will post the points now

Regards
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

777 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