Solved

Acces/Excel Automation Best Practices referrals

Posted on 2007-04-06
3
201 Views
Last Modified: 2007-05-09
I don't have an immediate issue per se, so I'm planning on splitting points between the best three or four comments.

Main question:  Is there a definitive book/reference/website for handling complex MS Office automation subjects?  My specific area is automating Excel from Access.  

I’ve developed an Access app that, in one sub for example, creates an xls, populates data and runs (Analysis Toolpak) regressions in a series of sheets, then saves it.  Worked like a charm on a one-up basis.  However, when the sub is called multiple times (40-50) as code loops through a recordset of selected states, it would hang intermittently.

After banging my head against the wall the requisite number of times (392), I ascertained the problem – the sub as written created an Excel application instance, toggled the Toolpak off and on, ran through the rest of the tasks, and then closed everything up, quit the app and set the references to nothing.  

Unfortunately, that doesn’t seem to happen quickly enough when the next loop/request is coming in at the speed of light.  

As a result, the Toolpak apparently didn’t always get started, so the code would error at unpredictable intervals (about 7 or 8 out of 45 files) when it hit the first regression call in a workbook.  If the user clicked “OK” to the resulting error message, the code would start another instance of Excel in the next loop and go merrily on its way, leaving an orphaned  instance of Excel running.

The fix was to start the Excel app instance and toggle the Toolpak addin in the calling routine (once!), then pass the app as a (excel.application) parameter to the sub with each loop, then kill it when the main routine completes (again, once).

So the question is – how should I have known that?  I couldn’t find anything definitive on experts-exchange (although I got a hint from a thread about a sub that worked from debug but not when run from a form that eventually got me on track).  Is there a Best Practices or help screen I’m not aware of that I should’ve stumbled onto sooner?  Is it always a good idea to try to minimize the number of automation objects you instantiate and my mother just never told me?  Is there a really good book or reference material or website that goes deep into this?

Thanks in advance for your thoughts and suggestions.

JN
0
Comment
Question by:genaughton
  • 2
3 Comments
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 18869892
You couldn't have known it, but if you had considered how to optimise your code, you should have come to the conclusion that launching and quitting Excel in every loop isn't optimum.

I don't know of a book on this - I own no books on Access programming - but this link may be of use for you:
http://www.4tops.com/ms_access_tips/exobjpr.htm

Shamil Salakhetdinov is a true expert in this field:
http://www.4tops.com/ms_access_tips/expexcel.htm

/gustav
0
 
LVL 1

Author Comment

by:genaughton
ID: 19058429
gustav,

 Thanks for your input.  I was hoping for more input from the community at large, and although I know starting and stopping an automation server multiple times isn't ideal, I was looking for some guidelines on the trade-offs involved.

thanks again,

JN
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 19058474
You are welcome!

/gustav
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)

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now