Avatar of GNOVAK
GNOVAKFlag for United States of America asked on

Access 2010: Creating subreport with VBA with change in Query

I'm using Access 2010 and giving the user a method of selecting records to view AND the fields to view.  
I create a query on the fly, always naming it the same.  The field names can change as can the where clause.  I handle all this through VBA quite smoothly.

Now the tough part - I wish to display the results in a data view subform. This will allow the user to size and sort.
Two questions:
1) When I set up the subreport and tell it to base it off of a query, it uses the fields that exist AT THE TIME of creation.  My routine changes the query and the fields. I would like the subreport to use the same named query but the fields have changed.  I'm thinking I can place fields in the detail section of the subreport on the fly, requery and everything should be good.
Does anyone know how to do something like this?  I'm not talking about new records - that's handled by by where clause in the query and it's working great...as a query.  Problem is that the fields have changed as well.

2) is there a way for the autosize to use column headers as well as data to autosize the columns?

Jerry
Microsoft Access

Avatar of undefined
Last Comment
GNOVAK

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Jeffrey Coachman

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Jeffrey Coachman

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Jeffrey Coachman

<Asside>
I know it seems like a nice thing to do to give the users this much flexibility...

But if they need this much control, then why not just teach them to build queries on their own?

What I try to do is create systems that will encompass all of the fields a use might need.
Having controls generate at runtime creates too much complexity to the App.
(You have to worry about "overflow" errors (where the size of your shiny new control might exceed the limits of the form, and generate an error) , or this control may cover/overlap other controls.
Not for the faint of heart...
Most Access developers will warn against doing this for production databases...

JeffCoachman
ASKER
GNOVAK

Is it possible to size a column in the data view via dba?
I'm thinking perhaps of loading all columns, setting the default size to 0 and only correct sizing the fields selected....
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
GNOVAK

So I could create a form with all potential fields,and, as I make the query, I could set those field widths and zero the others... That might work.
Ill have to name all the text boxes on the form. How do I loop through and change them?
I'm thinking something like this in the form itself
For count = 1 to me. Columns.count
   Me.columns.item(count) =<some name>
Next
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy