Okay, my turn to feel dumb... Maybe I should cross post this in the
Word programming NG...
I can get the contents of multiple columns and write them to an Access
table without a problem, BUT I get two unreadable characters at the
end of the text, which I'm not sure how to get rid of...
and this REALLY needs error handling...
Public Sub GetTableFromWord(ByVal strDoc As String, Optional ByVal
intTableNo As Integer = 1)
' Sample Call (watch the wrap... should be one line):
'GetTableFromWord "C:\Documents and Settings\Pieter\My Documents
\Application Support Specialist Gaylord Entertainment.doc"
'---Access Variables
Dim r As DAO.Recordset
'---Word Variables
Dim appWord As Word.Application
Dim docWord As Word.Document
Dim tbl As Word.Table
Dim docRow As Word.Row
'---create the append-only recordset to write to the Access Table
"tblWordDoc"
Set r = DBEngine(0)(0).OpenRecordset("tblWordDoc", dbOpenTable,
dbAppendOnly)
'---open Word... I should really use fIsAppRunning() from Access
Web... shame on me!
Set appWord = New Word.Application
appWord.Documents.Open strDoc
appWord.Documents(strDoc).Activate
Set docWord = appWord.ActiveDocument
Set tbl = ActiveDocument.Tables(intTableNo)
For Each docRow In tbl.Rows
Debug.Print docRow.Cells(1).Range
r.AddNew
r.Fields("ColumnA") = docRow.Cells(1).Range.Text
r.Fields("ColumnB") = docRow.Cells(2).Range.Text
r.Update
Next docRow
r.Close
Set r = Nothing
Set tbl = Nothing
docWord.Close
Set docWord = Nothing
appWord.Quit
Set appWord = Nothing
'open the table so I can see the new records. Bad to do in a real
DB, but this is a test.
DoCmd.OpenTable "tblWordDoc"
End Sub
Can this be done with ADO? I know you can send data using ADO, like in
Developer's Handbook, but what about reading using some ADO object,
like a textstream? (Watch me hijack the thread;... I really ought to
start a new one!)
Thanks,
Pieter