Solved

MS Access RecordSets

Posted on 2014-10-30
8
172 Views
Last Modified: 2014-10-30
I'm using Access 2010 as a frontend to a remote SQL Server.  the tables from SQL Server are linked.  I'm trying to output data to Excel.  Getting it to Excel is not the problem but the fact that its requires the data coming from SQL Server be chopped up in many different ways is...  The process is for users to select records that will be exported into and excel report.  It could be 1 record or 20k records...  I have a form that displays the selected records and a button "Export"  that starts the process of creating the multi-tabbed Excel.  Each tab of the excel xls requires various filtering and summing and logic to be applied to the selected data set.  It's taking way to long to create the file and I believe its due to having to run a number of queries on the same data on the server over and over again.

My question is this... Seeing that I have the selected data is sitting in a form grid can I not use that data to perform all the filtering and summing rather than go back to the server 15 times?

If so, I'm trying to figure out how I would do that.
0
Comment
Question by:keschuster
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 40413553
You could copy the main data from SQL Server to a local table and run your exports using this.

/gustav
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 40413559
You might find it easier and quicker to pull the necessary data from the server into a temporary table that can be manipulated for your exports.  I wrote an article on using temporary tables a while back, and this was one of the scenarios I described where using a temp table can be more efficient.
0
 

Author Comment

by:keschuster
ID: 40413612
I actually use temp tables in this app - very sparingly.  My fear is as a user runs this app all day inserting and deleting records into this temp table Access will swell and exceed the 2gb limit....    If there was a way to avoid this issue aside from asking the user to compact repair every hour then I'm all it.  I just don't see how.

Because of this I starting thinking about the grids I'm creating based on queries sent to SQL Server.  I already have the data I need for the report sitting right there in front of me in a grid.  Can't i use that in someway to code against it and create the various recordsets I need to push into Excel?
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 49

Expert Comment

by:Gustav Brock
ID: 40413640
If by grid you mean a form in datasheet view, you have access to the current recordset.
This you can write to a temp table and export this.

Temp tables can be held in a linked local database which you overwrite with empty data when the user opens your frontend.

/gustav
0
 
LVL 35

Expert Comment

by:PatHartman
ID: 40413874
Instead of using TransferSpreadsheet to copy the data to Excel, you can use OLE automation.  You would loop through the recordset clone of the form and populate the sheets a row at a time.  You'll need to decide for each row, which sheet to add it to so you'll need to keep track of your row position on all the sheets since you are populating them in parallel.
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 40413891
If you use the subroutine mentioned in my article, the act of creating the temp table, either in the front end or in a separate bd linked to your front end, can be reduced to a single line of code.  It even has arguments that let you determine how fresh you want the data.
0
 

Author Comment

by:keschuster
ID: 40413936
So Dale - your code will create the linked DB and table as needed. presumably the temp table gets dropped leaving the holding DB still there.  When the need to create the temp table again you can force it to create/overwrite a new DB and table that gets linked all over again.

Is that basically the idea?
0
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 40413979
Right now, the act of delinking the table and deleting the file: YourAppName_temp.accdb
Is left up to you.  I usually do that with a subroutine i call when the application closes.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question