[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Filter query from access form using variable

Posted on 2012-12-31
5
Medium Priority
?
395 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
  • 3
5 Comments
 
LVL 49

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Suggested Courses

873 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