Link to home
Start Free TrialLog in
Avatar of k2jeff
k2jeffFlag for United States of America

asked on

Create Table or Query from Open Recordset?

I have a continuous form that the user can sort and filter to the nth degree.  They need to print a report that is based on the forms underlying recordset after they have filtered and sorted it the way they want it to look.   Is there an easy way to create a table or query from the form's recordset clone?  That way I could just have the report's record source point to this new table or query.  

This app is DAO, but I'm open to any method that would save me coding time for a createtabledef option with a lenghtly and complex SQL strings.  The recordset for the form and report is a complex query with multiple joins and parameters.  A maketable query is an option, but this will be a complex hassel because all of the field criteria references for the filters and sorts.

It seems like there should be an easy way to enumerate the fields in a recordset clone object and save it as a persistent table or query object.  However, I cannot find a reasonable way to do this.  Basically I just need to make the report's record souce the same as the form's resulting recordset after the form filters and sorts have been selected.  

Any help would be very much appreciated!

K2Jeff
Avatar of nico5038
nico5038
Flag of Netherlands image

You can just pass the filter when opening the report like:

docmd.OpenReport "reportname",acViewPreview,,me.filter

Need more info ?

Nic;o)
ASKER CERTIFIED SOLUTION
Avatar of nico5038
nico5038
Flag of Netherlands 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
Avatar of k2jeff

ASKER

Nico, Thanks for the quick response.  I will give that a try.  I thought the FilterName argument had to be a reference to an existing query object.  I didn't think it would work to pass it the form's filter.  But, I've never tried it before!

K2Jeff
The me.filter will contain the filter build using the right-click popup.
The only trouble you can run into is the fact that Access will add a tablename to the fields when there's a JOIN between tables with the same fieldnames.
When you use however the same query as for the report, this shouldn't be a problem.

Personally I use in general a subform for filtering and "echo" the value to the mainform to show it to the user.
For advanced users I even allow the storing of the build filter in a table so they can "re-use" it.

Nic;o)