Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Acces/Excel Automation Best Practices referrals

Posted on 2007-04-06
3
Medium Priority
?
229 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 1000 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

730 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