Link to home
Start Free TrialLog in
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
ASKER CERTIFIED SOLUTION
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
<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
Avatar of GNOVAK

ASKER

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
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GNOVAK

ASKER

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