![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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 throwsan ' 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/libr...8VS.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. |
#3
| |||
| |||
|
|
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/libr...8VS.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/micro...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 (AT) FortuneJames (DOT) com |
#4
| |||
| |||
|
|
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... (AT) FortuneJames (DOT) com |
#5
| |||
| |||
|
|
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... (AT) FortuneJames (DOT) 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...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 (AT) FortuneJames (DOT) com |
![]() |
| Thread Tools | |
| Display Modes | |
| |