Hide/Unhide fields in the query Output

K

kris

Hello,
I have a list box in a form that helps me to select a "Field" in the
table.I want the query output to display only that field and hide the rest of
the fields for all records.
I have tried putting the "Forms![Table2]![category] " in the the query
display field but that doesnt work.The SQL view looks like this

SELECT [Forms]![Table2]![category] AS Expr1
FROM Table1;
 
K

kris

Hey Duane,
I tried it but it's giving me a runtime error-2186.
I put the code in a module and made it run through a macro.(using run Code
action).


Thanks Kris

Duane Hookom said:
Your solution won't work. You could use a little DAO code to change the SQL
of the saved querydef.

Dim strSQL as String
strSQL = "SELECT [" & [Forms]![Table2]![category] & _
"] AS MyColumn FROM Table1;"
CurrentDb.QueryDefs("qselMyQuery").SQL = strSQL

--
Duane Hookom
Microsoft Access MVP


kris said:
Hello,
I have a list box in a form that helps me to select a "Field" in the
table.I want the query output to display only that field and hide the rest of
the fields for all records.
I have tried putting the "Forms![Table2]![category] " in the the query
display field but that doesnt work.The SQL view looks like this

SELECT [Forms]![Table2]![category] AS Expr1
FROM Table1;
 
K

kris

Hey Daune,
Thank you very much.It works fine.
The problem was with my code.


kris said:
Hey Duane,
I tried it but it's giving me a runtime error-2186.
I put the code in a module and made it run through a macro.(using run Code
action).


Thanks Kris

Duane Hookom said:
Your solution won't work. You could use a little DAO code to change the SQL
of the saved querydef.

Dim strSQL as String
strSQL = "SELECT [" & [Forms]![Table2]![category] & _
"] AS MyColumn FROM Table1;"
CurrentDb.QueryDefs("qselMyQuery").SQL = strSQL

--
Duane Hookom
Microsoft Access MVP


kris said:
Hello,
I have a list box in a form that helps me to select a "Field" in the
table.I want the query output to display only that field and hide the rest of
the fields for all records.
I have tried putting the "Forms![Table2]![category] " in the the query
display field but that doesnt work.The SQL view looks like this

SELECT [Forms]![Table2]![category] AS Expr1
FROM Table1;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top