SOLVED

Querying values by choosing a field from List of fields/columns name from a combobox,

%3CLINGO-SUB%20id%3D%22lingo-sub-1150538%22%20slang%3D%22en-US%22%3EQuerying%20values%20by%20choosing%20a%20field%20from%20List%20of%20fields%2Fcolumns%20name%20from%20a%20combobox%2C%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1150538%22%20slang%3D%22en-US%22%3EDear%20master%20of%20Access%3CBR%20%2F%3EI%20have%20a%20question%20hope%20you%20will%20find%20it%20interesting%20to%20answer%20it.%3CBR%20%2F%3EI%20have%20a%20form%20which%20have%202%20combo%20boxes%2C%20one%20got%20list%20of%20Fields%2Fcolumns%20from%20my%20table%2Fquery.%20I%20am%20trying%20to%20choose%20a%20field%20from%20combo%20box%20and%20then%20based%20on%20that%20field%20I%20pass%20a%20value%20from%20another%20combo%20box%20.%20But%20at%20the%20moment%20I%20am%20not%20able%20to%20do%20it%20and%20I%20can't%20figure%20out%20how%20to%20make%20it%20work.%3CBR%20%2F%3EAny%20help%20will%20be%20much%20appreciated.%20The%20idea%20is%20I%20could%20choose%20any%20field%20from%20combo%20box%20and%20pass%20the%20value%20to%20accordingly%20and%20get%20result%20in%20a%20form%20with%20docmd......%3CBR%20%2F%3EThank%20you.%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1150538%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAccess%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1150618%22%20slang%3D%22en-US%22%3ERe%3A%20Querying%20values%20by%20choosing%20a%20field%20from%20List%20of%20fields%2Fcolumns%20name%20from%20a%20combobox%2C%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1150618%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F468421%22%20target%3D%22_blank%22%3E%40Asad_khan1971%3C%2FA%3E%26nbsp%3BThis%20is%20a%20very%20common%20function.%20We%20usually%20refer%20to%20it%20as%20%22Cascading%20Combo%20Boxes%22.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EA%20search%20on%20that%20term%20will%20turn%20up%20a%20plethora%20of%20explanations%20and%20examples.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1150839%22%20slang%3D%22en-US%22%3ERe%3A%20Querying%20values%20by%20choosing%20a%20field%20from%20List%20of%20fields%2Fcolumns%20name%20from%20a%20combobox%2C%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1150839%22%20slang%3D%22en-US%22%3EI%20don't%20think%20my%20explanation%20of%20the%20problem%20was%20elaborate%20enough.%20I%20try%20again.%3CBR%20%2F%3ESo%20I%20have%20a%20combo%20box%20which%20lists%20the%20fields%20from%20a%20table%20not%20the%20values%20of%20a%20colum.%20My%20other%20combo%20box%20contains%20the%20values%20of%20fields%20which%20are%20listed%20in%20the%20combo%20box%20one.%20What%20I%20am%20trying%20here%20is%20select%20a%20field%20name%20from%20first%20combo%20and%20then%20select%20value%20from%20the%20second%20combo%20and%20then%20click%20a%20button%20which%20will%20open%20another%20form%20to%20show%20the%20records%20based%20on%20criteria%20passed.%20I%20can%20do%20it%20with%20value%20combos%20but%20combo%20with%20table%20field%20name%20with%20other%20combo%20contains%20value%20I%20am%20can't%20figure%20out%20how%20to%20do%20it.%20Sorry%20it's%20not%20the%20case%20of%20cascading%20combos.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1152713%22%20slang%3D%22en-US%22%3ERe%3A%20Querying%20values%20by%20choosing%20a%20field%20from%20List%20of%20fields%2Fcolumns%20name%20from%20a%20combobox%2C%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1152713%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F468421%22%20target%3D%22_blank%22%3E%40Asad_khan1971%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%22...%3CSPAN%3E%26nbsp%3Bcombo%20box%20which%20lists%20the%20fields%20from%20a%20table%26nbsp%3B...%22%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%22My%20other%20combo%20box%20contains%20the%20values%20of%20fields%20which%20are%20listed%20in%20the%20combo%20box%20one%22%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EThat's%20a%20first%20for%20me.%20I%20never%20heard%20of%20that%20approach%20before%2C%20so%20I'm%20curious%20as%20to%20why%20you%20do%20this.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EI%20suspect%20what%20you%20have%20is%20a%20table%20with%20fields%20like%20%22Data1%22%2C%20%22Data2%22%2C%20where%20you're%20encoding%20values%20into%20the%20names%20of%20the%20fields%3F%20Is%20that%20the%20case%3F%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EIf%20so%2C%20that's%20the%20real%20problem%20and%20this%20rather%20unconventional%20approach%20to%20cascading%20combo%20boxes%20(and%20that%20is%2C%20indeed%2C%20the%20same%20principle)%20is%20a%20result%20of%20that%20table%20design.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3ESo%2C%20what%20ARE%20some%20examples%20of%20the%20real%20field%20names%20in%20this%20table%3F%20And%20what%20are%20some%20examples%20of%20the%20values%20in%20those%20fields%20you%20want%20for%20the%20second%20combo%20box%3F%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1152955%22%20slang%3D%22en-US%22%3ERe%3A%20Querying%20values%20by%20choosing%20a%20field%20from%20List%20of%20fields%2Fcolumns%20name%20from%20a%20combobox%2C%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1152955%22%20slang%3D%22en-US%22%3EIt's%20a%20kind%20of%20survey%20db%20the%20example%20of%20field%20names%20are%3A%3CBR%20%2F%3EField%2Fcolumn%20name%3A%20Was%20data%20synchronised%3F%3CBR%20%2F%3EValue%3A%20yes%20or%20no%3CBR%20%2F%3EPlease%20see%20attached%20image.%3CBR%20%2F%3EBasically%20it's%20a%20try%20to%20create%20a%20query%20tool.%20So%20user%20could%20select%20a%20field%20choose%20the%20criteria%20for%20the%20field...%3CBR%20%2F%3EThanks%20for%20your%20time%20and%20interest%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1152960%22%20slang%3D%22en-US%22%3ERe%3A%20Querying%20values%20by%20choosing%20a%20field%20from%20List%20of%20fields%2Fcolumns%20name%20from%20a%20combobox%2C%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1152960%22%20slang%3D%22en-US%22%3EPlease%20also%20note%20value%20in%20combo%202%20are%20already%20there%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1152981%22%20slang%3D%22en-US%22%3ERe%3A%20Querying%20values%20by%20choosing%20a%20field%20from%20List%20of%20fields%2Fcolumns%20name%20from%20a%20combobox%2C%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1152981%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F468421%22%20target%3D%22_blank%22%3E%40Asad_khan1971%3C%2FA%3E%26nbsp%3BAs%20I%20feared%2C%20it%20sounds%20like%20you%20have%20a%20%22spreadsheet%20style%22%20table.%20That%20is%20fine%20for%20Excel%2C%20but%20not%20for%20a%20Relational%20Database%20Application%2C%20such%20as%20those%20built%20in%20Access.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20solution%20--%20the%20one%20that%20will%20pay%20off%20most%20in%20the%20long%20run%20--%20is%20to%20correct%20this%20flawed%20table%20design%2C%20as%20described%20in%20%3CA%20href%3D%22https%3A%2F%2Frogersaccessblog.blogspot.com%2Fsearch%2Flabel%2FProblems%2520With%2520Repeated%2520Columns%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ethis%20series%20of%20blog%20posts%3C%2FA%3E.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFields%20in%20this%20table%20should%20actually%20be%20records%20in%20a%20single%20field%2C%20or%20a%20few%20fields%2C%20depending%20on%20what%20is%20in%20each%20of%20them.%20Following%20the%20correction%20to%20the%20underlying%20table%2C%20this%20particular%20problem%20with%20combo%20boxes%20will%20simply%20not%20exist.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1153978%22%20slang%3D%22en-US%22%3ERe%3A%20Querying%20values%20by%20choosing%20a%20field%20from%20List%20of%20fields%2Fcolumns%20name%20from%20a%20combobox%2C%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1153978%22%20slang%3D%22en-US%22%3EThank%20you%20sir%2C%20with%20utmost%20respect%2C%20I%20don't%20think%20I%20am%20able%20to%20convey%20my%20point.%20My%20db%20is%20working%20fine%2C%20this%20was%20just%20an%20idea.%3CBR%20%2F%3EI%20am%20sorry%20it's%20all%20my%20fault.%3CBR%20%2F%3EThank%20you%20again%20for%20your%20time.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1155659%22%20slang%3D%22en-US%22%3ERe%3A%20Querying%20values%20by%20choosing%20a%20field%20from%20List%20of%20fields%2Fcolumns%20name%20from%20a%20combobox%2C%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1155659%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F468421%22%20target%3D%22_blank%22%3E%40Asad_khan1971%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20think%20I%20understand%20pretty%20well.%20Over%20the%20last%2025%20years%20of%20working%20with%20Access%20Relational%20Database%20Applications%2C%20I've%20seen%20this%20mistaken%20approach%20to%20table%20design%20many%2C%20many%20times.%20Excel%20tables%26nbsp%3B%20have%20multiple%20columns%2C%20each%20of%20which%20is%20one%20kind%20of%20thing.%20You%20only%20offered%20one%20column%20name%2C%20but%20that's%20enough%20to%20give%20us%20the%20picture.%20That%20one%20is%20a%20yes%2Fno%20question%2C%20is%20it%20not%3F%20And%20you%20have%20many%20other%20fields%20like%20it%2C%20all%20of%20them%20being%20yes%2Fno%20questions%2C%20do%20you%20not%3F%20That%20is%20the%20problem.%20It%20is%20the%20reason%20you%20are%20trying%20to%20create%20this%20cascading%20combo%20box%20set%20up%20to%20compensate%20for%20that%20design%20problem.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20could%20offer%20a%20work-around%20that%20would%20look%20up%20the%20field%20in%20that%20table%20and%20use%20that%20to%20populate%20the%20second%20combo%20box%20with%20values%2C%20but%20that%20would%20be%20a%20work-around%2C%20not%20a%20solution.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPlease%20invest%20some%20time%20in%20learning%20more%20about%20Relational%20Database%20Design.%20Your%20survey%20will%20be%20significantly%20better.%3CBR%20%2F%3E%3CBR%20%2F%3EHere%20is%20a%20link%20to%20%3CA%20href%3D%22http%3A%2F%2Fwww.rogersaccesslibrary.com%2Fforum%2Ftopic3.html%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eone%20of%20the%20more%20popular%20survey%20templates%3C%2FA%3E.%20It's%20been%20downloaded%20thousands%20of%20times.%20It'll%20be%20useful%20to%20you%20as%20well%2C%20I%20believe.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor
Dear master of Access
I have a question hope you will find it interesting to answer it.
I have a form which have 2 combo boxes, one got list of Fields/columns from my table/query. I am trying to choose a field from combo box and then based on that field I pass a value from another combo box . But at the moment I am not able to do it and I can't figure out how to make it work.
Any help will be much appreciated. The idea is I could choose any field from combo box and pass the value to accordingly and get result in a form with docmd......
Thank you.
8 Replies

@Asad_khan1971 This is a very common function. We usually refer to it as "Cascading Combo Boxes".

 

A search on that term will turn up a plethora of explanations and examples.

I don't think my explanation of the problem was elaborate enough. I try again.
So I have a combo box which lists the fields from a table not the values of a colum. My other combo box contains the values of fields which are listed in the combo box one. What I am trying here is select a field name from first combo and then select value from the second combo and then click a button which will open another form to show the records based on criteria passed. I can do it with value combos but combo with table field name with other combo contains value I am can't figure out how to do it. Sorry it's not the case of cascading combos.

@Asad_khan1971 

 

"... combo box which lists the fields from a table ..."

 

"My other combo box contains the values of fields which are listed in the combo box one"

 

That's a first for me. I never heard of that approach before, so I'm curious as to why you do this.

 

I suspect what you have is a table with fields like "Data1", "Data2", where you're encoding values into the names of the fields? Is that the case?

 

If so, that's the real problem and this rather unconventional approach to cascading combo boxes (and that is, indeed, the same principle) is a result of that table design.

 

So, what ARE some examples of the real field names in this table? And what are some examples of the values in those fields you want for the second combo box?

It's a kind of survey db the example of field names are:
Field/column name: Was data synchronised?
Value: yes or no
Please see attached image.
Basically it's a try to create a query tool. So user could select a field choose the criteria for the field...
Thanks for your time and interest

Please also note value in combo 2 are already there
Best Response confirmed by Asad_khan1971 (Occasional Contributor)
Solution

@Asad_khan1971 As I feared, it sounds like you have a "spreadsheet style" table. That is fine for Excel, but not for a Relational Database Application, such as those built in Access.

 

The solution -- the one that will pay off most in the long run -- is to correct this flawed table design, as described in this series of blog posts.

 

Fields in this table should actually be records in a single field, or a few fields, depending on what is in each of them. Following the correction to the underlying table, this particular problem with combo boxes will simply not exist.

Thank you sir, with utmost respect, I don't think I am able to convey my point. My db is working fine, this was just an idea.
I am sorry it's all my fault.
Thank you again for your time.

@Asad_khan1971 

 

I think I understand pretty well. Over the last 25 years of working with Access Relational Database Applications, I've seen this mistaken approach to table design many, many times. Excel tables  have multiple columns, each of which is one kind of thing. You only offered one column name, but that's enough to give us the picture. That one is a yes/no question, is it not? And you have many other fields like it, all of them being yes/no questions, do you not? That is the problem. It is the reason you are trying to create this cascading combo box set up to compensate for that design problem. 

 

I could offer a work-around that would look up the field in that table and use that to populate the second combo box with values, but that would be a work-around, not a solution.

 

Please invest some time in learning more about Relational Database Design. Your survey will be significantly better.

Here is a link to one of the more popular survey templates. It's been downloaded thousands of times. It'll be useful to you as well, I believe.