Link to home
Start Free TrialLog in
Avatar of dsoderstrom

asked on

Problem with GetObject function in MS Access

I am trying to open excel  from vba code in Access 2010 using the GetObject function.
My code is as follows:
      dim xlObj as Object
      Set xlObj = GetObject(, "excel.application")

I get the following error  on the second line:

      Run-time error '429':
      ActiveX component can't create object

What is strange is that this was working for a few iterations and now it doesn't.
The first time if failed I did a decompile of the data base and that got it to work for one time.  But then if failed with the same message again.

Any ideas on what is causing this?
Avatar of Rgonzo1971

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dsoderstrom


Wow, I guess that should have been obvious to me!
Thank you for the help.
Generally, I put an error handler at the beginning of the code module.

Then I use the GetObject syntax to set the reference to an existing instance of Excel.  If that raises an error, it goes to the error handler, where I use syntax similar to:

If Err.Num = x  then   'don't remember the error code off the top of my head
    Set xlObj = CreateObject("Excel.Application")
    Resume Next