Form based on query when query columns change

User avatar
Abraxus
3StarLounger
Posts: 254
Joined: 01 Mar 2010, 17:34
Location: Blue Springs, MO

Form based on query when query columns change

Post by Abraxus »

I am building a Query Builder for some people here at work.

They can choose from 2 - 20 fields to show in their results.

Not everyone that will use this is familiar with Access, so I'm afraid they will close the entire app rather than the query that pops up for them so I thought of having a form pop up that showed them their results, but also offered a CLOSE QUERY button.

How can I have that sort of form when the columns are not the same from query to query?

Thanks!
Morgan

User avatar
HansV
Administrator
Posts: 78493
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Form based on query when query columns change

Post by HansV »

It'd be quite a bit of work, but you could create a form with 20 text boxes.
Using code, set the record source of the form to the query you created, and set the control source of as many text boxes as you need to the fields of the query. Hide the rest of the text boxes.

If you want to be able to handle lookup fields, you'd need to use combo boxes too and set their row source. That would be more complicated.
Best wishes,
Hans

JohnH
3StarLounger
Posts: 287
Joined: 09 Mar 2010, 23:16
Location: Canberra Australia

Re: Form based on query when query columns change

Post by JohnH »

Another option is to display the query results within a subform control.
The source object of a subform control is usually another form, but it can be a query.

I attach a little demo.

I recently tried to use this where the query that was being built was a cross tab query. Access did not like this (as the number of columns varied according to the data), so I had to take the route of Hans suggestion. Had an unbound form and set the control source of the various text boxes via code. The code for unbound cross tab reports could be adapted for use with a form
You do not have the required permissions to view the files attached to this post.
Regards

John