Solved

Acces/Excel Automation Best Practices referrals

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

803 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