f



solving a "ActiveX component can't create object or return reference to this object Run Time Error 429"

I open Access 2007, open the mydatabase.accdb database, run the below 
code as a macro and it runs fine.

But, if I open a Word 2007 document, try to run this as a macro, I get 
the error "Run Time Error 429 ActiveX component can't create object or 
return reference to this object". on the line where I am trying to open 
a handle to the database at OpenDatabase("C:\mydatabase.accdb").

I want the below part to run in a Word document so it can read the data 
in the last column of every row of all the tables in a document, 
populate a recordset with the values and then insert it in a Access 2007 
table(Table1).

  Sub ReturnTableText()

  Dim oTable As Table
  Dim oRow As Row
  Dim oRng As Range
  Dim sText As String
  Dim count As Integer
  Dim dbMyDB As DAO.Database
  Dim myRecordSet As DAO.Recordset


  Set dbMyDB = OpenDatabase("C:\mydatabase.accdb") ' this line throws an 
' error Run Time Error 429 ActiveX component can't create object or
  ' return reference to this object

  Set myRecordSet = dbMyDB.OpenRecordset("Table1", dbOpenDynaset)

  sText = ""
  count = 0

  For Each oTable In ActiveDocument.Tables

  For Each oRow In oTable.Rows

  If oRow.Cells.count  1 Then
  Set oRng = oRow.Cells(oRow.Cells.count).Range
  oRng.End = oRng.End - 1
  myRecordSet.Fields(count).Value = oRng.Text & Chr(44)
  MsgBox myRecordSet.Fields(count).Value
  count = count + 1

  End If

  Next oRow

  Next oTable

  myRecordSet.Close
  dbMyDB.Close

  End Sub

  I checked the documentation at
  http://msdn.microsoft.com/en-us/library/aa231060%28VS.60%29.aspx
  but could not solve it. The registry seems proper and the required 
References are present, there is no missing reference.

  Any advice would be appreciated on how to solve this error.







0
r
5/31/2010 11:21:36 PM
comp.databases.ms-access 42611 articles. 0 followers. Post Follow

4 Replies
2893 Views

Similar Articles

[PageSpeed] 50

On May 31, 7:21=A0pm, r <r...@r.com> wrote:
> I open Access 2007, open the mydatabase.accdb database, run the below
> code as a macro and it runs fine.
>
> But, if I open a Word 2007 document, try to run this as a macro, I get
> the error "Run Time Error 429 ActiveX component can't create object or
> return reference to this object". on the line where I am trying to open
> a handle to the database at OpenDatabase("C:\mydatabase.accdb").
>
> I want the below part to run in a Word document so it can read the data
> in the last column of every row of all the tables in a document,
> populate a recordset with the values and then insert it in a Access 2007
> table(Table1).
>
> =A0 Sub ReturnTableText()
>
> =A0 Dim oTable As Table
> =A0 Dim oRow As Row
> =A0 Dim oRng As Range
> =A0 Dim sText As String
> =A0 Dim count As Integer
> =A0 Dim dbMyDB As DAO.Database
> =A0 Dim myRecordSet As DAO.Recordset
>
> =A0 Set dbMyDB =3D OpenDatabase("C:\mydatabase.accdb") ' this line throws=
 an
> ' error Run Time Error 429 ActiveX component can't create object or
> =A0 ' return reference to this object
>
> =A0 Set myRecordSet =3D dbMyDB.OpenRecordset("Table1", dbOpenDynaset)
>
> =A0 sText =3D ""
> =A0 count =3D 0
>
> =A0 For Each oTable In ActiveDocument.Tables
>
> =A0 For Each oRow In oTable.Rows
>
> =A0 If oRow.Cells.count =A01 Then
> =A0 Set oRng =3D oRow.Cells(oRow.Cells.count).Range
> =A0 oRng.End =3D oRng.End - 1
> =A0 myRecordSet.Fields(count).Value =3D oRng.Text & Chr(44)
> =A0 MsgBox myRecordSet.Fields(count).Value
> =A0 count =3D count + 1
>
> =A0 End If
>
> =A0 Next oRow
>
> =A0 Next oTable
>
> =A0 myRecordSet.Close
> =A0 dbMyDB.Close
>
> =A0 End Sub
>
> =A0 I checked the documentation at
> =A0http://msdn.microsoft.com/en-us/library/aa231060%28VS.60%29.aspx
> =A0 but could not solve it. The registry seems proper and the required
> References are present, there is no missing reference.
>
> =A0 Any advice would be appreciated on how to solve this error.

In:

http://groups.google.com/group/microsoft.public.access/browse_frm/thread/80=
e2331aecd64658

I said:

"I vaguely recall that in earlier versions of Word, I think I had to
use the Workspace object within Word VBA in order to interact with
Access data correctly."

In the same post I also said:

"I haven't used Word 2007 yet so I'll refrain from making
recommendations about the best course of action when ignorance is
present."

I'll leave it at that.

James A. Fortune
CDMAPoster@FortuneJames.com
0
James
6/1/2010 1:43:30 AM
On 5/31/2010 9:43 PM, James A. Fortune wrote:
> On May 31, 7:21 pm, r<r...@r.com>  wrote:
>> I open Access 2007, open the mydatabase.accdb database, run the below
>> code as a macro and it runs fine.
>>
>> But, if I open a Word 2007 document, try to run this as a macro, I get
>> the error "Run Time Error 429 ActiveX component can't create object or
>> return reference to this object". on the line where I am trying to open
>> a handle to the database at OpenDatabase("C:\mydatabase.accdb").
>>
>> I want the below part to run in a Word document so it can read the data
>> in the last column of every row of all the tables in a document,
>> populate a recordset with the values and then insert it in a Access 2007
>> table(Table1).
>>
>>    Sub ReturnTableText()
>>
>>    Dim oTable As Table
>>    Dim oRow As Row
>>    Dim oRng As Range
>>    Dim sText As String
>>    Dim count As Integer
>>    Dim dbMyDB As DAO.Database
>>    Dim myRecordSet As DAO.Recordset
>>
>>    Set dbMyDB = OpenDatabase("C:\mydatabase.accdb") ' this line throws an
>> ' error Run Time Error 429 ActiveX component can't create object or
>>    ' return reference to this object
>>
>>    Set myRecordSet = dbMyDB.OpenRecordset("Table1", dbOpenDynaset)
>>
>>    sText = ""
>>    count = 0
>>
>>    For Each oTable In ActiveDocument.Tables
>>
>>    For Each oRow In oTable.Rows
>>
>>    If oRow.Cells.count  1 Then
>>    Set oRng = oRow.Cells(oRow.Cells.count).Range
>>    oRng.End = oRng.End - 1
>>    myRecordSet.Fields(count).Value = oRng.Text&  Chr(44)
>>    MsgBox myRecordSet.Fields(count).Value
>>    count = count + 1
>>
>>    End If
>>
>>    Next oRow
>>
>>    Next oTable
>>
>>    myRecordSet.Close
>>    dbMyDB.Close
>>
>>    End Sub
>>
>>    I checked the documentation at
>>   http://msdn.microsoft.com/en-us/library/aa231060%28VS.60%29.aspx
>>    but could not solve it. The registry seems proper and the required
>> References are present, there is no missing reference.
>>
>>    Any advice would be appreciated on how to solve this error.
>
> In:
>
> http://groups.google.com/group/microsoft.public.access/browse_frm/thread/80e2331aecd64658
>
> I said:
>
> "I vaguely recall that in earlier versions of Word, I think I had to
> use the Workspace object within Word VBA in order to interact with
> Access data correctly."

Can you please explain how to do that?

I tried
Set dbMyDB = DBEngine.Workspaces(0).OpenDatabase("C:\mydatabase.accdb")

But, it did not work.


> In the same post I also said:
>
> "I haven't used Word 2007 yet so I'll refrain from making
> recommendations about the best course of action when ignorance is
> present."

> I'll leave it at that.

I saved the Word 2007 document as a Word 2003 document having extension 
".doc" but it still did not work.

Am I missing something?

Thanks for your reply.

> James A. Fortune
> CDMAPoster@FortuneJames.com

0
r
6/1/2010 1:12:58 PM
On Jun 1, 9:12=A0am, r <r...@r.com> wrote:

>
> Can you please explain how to do that?
>
> I tried
> Set dbMyDB =3D DBEngine.Workspaces(0).OpenDatabase("C:\mydatabase.accdb")
>
> But, it did not work.
>
> > In the same post I also said:
>
> > "I haven't used Word 2007 yet so I'll refrain from making
> > recommendations about the best course of action when ignorance is
> > present."
> > I'll leave it at that.
>
> I saved the Word 2007 document as a Word 2003 document having extension
> ".doc" but it still did not work.
>
> Am I missing something?
>
> Thanks for your reply.
>
> > James A. Fortune
> > CDMAPos...@FortuneJames.com

I don't remember the exact details and the original post is too old
for Google to bring up.

Perhaps look at the following example (VBA in Excel or Word should be
similar to each other):

http://support.microsoft.com/default.aspx?scid=3DKB;EN-US;q146607&

or try using ADODB.

If I find an example of old Word VBA code that reads or writes to an
Access database I'll post back.

James A. Fortune
CDMAPoster@FortuneJames.com
0
James
6/2/2010 7:15:59 PM
On 6/2/2010 3:15 PM, James A. Fortune wrote:
> On Jun 1, 9:12 am, r<r...@r.com>  wrote:
>
>>
>> Can you please explain how to do that?
>>
>> I tried
>> Set dbMyDB = DBEngine.Workspaces(0).OpenDatabase("C:\mydatabase.accdb")
>>
>> But, it did not work.
>>
>>> In the same post I also said:
>>
>>> "I haven't used Word 2007 yet so I'll refrain from making
>>> recommendations about the best course of action when ignorance is
>>> present."
>>> I'll leave it at that.
>>
>> I saved the Word 2007 document as a Word 2003 document having extension
>> ".doc" but it still did not work.
>>
>> Am I missing something?
>>
>> Thanks for your reply.
>>
>>> James A. Fortune
>>> CDMAPos...@FortuneJames.com
>
> I don't remember the exact details and the original post is too old
> for Google to bring up.
>
> Perhaps look at the following example (VBA in Excel or Word should be
> similar to each other):
>
> http://support.microsoft.com/default.aspx?scid=KB;EN-US;q146607&
>
> or try using ADODB.
>
> If I find an example of old Word VBA code that reads or writes to an
> Access database I'll post back.
>
> James A. Fortune
> CDMAPoster@FortuneJames.com

Actually, don't worry I got it resolved. I had to check 'Microsoft DAO 
3.6 Object Library' in Tools->References.

Thanks for your reply.
0
r
6/6/2010 12:29:13 AM
Reply: