Solved

Acces/Excel Automation Best Practices referrals

Posted on 2007-04-06
3
213 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 50

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 50

Expert Comment

by:Gustav Brock
ID: 19058474
You are welcome!

/gustav
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
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 …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

740 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