Solved

Acces/Excel Automation Best Practices referrals

Posted on 2007-04-06
3
223 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 51

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 51

Expert Comment

by:Gustav Brock
ID: 19058474
You are welcome!

/gustav
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
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…

623 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