Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2007

    Unanswered: Word tables to access

    Hello everyone,

    I have a word document. Each page has two tables for well that have exactly the same structure on all 1000+ pages. I need to make a database out of those tables, where each page will become one record.

    Thanks in advance,


  2. #2
    Join Date
    Jan 2007
    Provided Answers: 12
    I'm not aware of any way to automatically link data in word to access. My gut feeling is that you have to type it all manually
    Word does not structure documents in the same way as, say, Excel.

    One idea I can give is:
    Open the word document in notepad and see if the file follows any logical structure.
    Home | Blog

  3. #3
    Join Date
    Jun 2007
    Hi George,

    Thanks for the answer. Is there a way to create a schema from Word to Access?

  4. #4
    Join Date
    Jan 2007
    California, USA
    Two things I would suggest trying.

    1. a) Save the document as a text file. The look at the document to see if there is a pattern there. This is a little different than what George suggested in that you would first change the document to text, then look for a pattern.
    b) Then, using VBA, read the text document and knowing the order of things within where the tables were, you might be able to "read" each entry in each table to create the fields and records from the table data.

    2. Try step b) above with the actual Word document. Using Access VBA, step through the table structure to create each record, data element by data element.

  5. #5
    Join Date
    Jun 2007
    Hello GolferGuy,

    I have looked at the txt file and it looks like the structure is the same for all pages.

    I have given the same question at experts exchange and was given the following code:

    Option Explicit

    Sub CopyToDatabase()
    Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim tbl As Word.Table
    Dim cl As Word.Cell
    Dim f As Integer
    Dim DB_path As String
    DB_path = "D:/data/water_project/water_cadastre/wells/armavir/"

    cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DB_path & "armavir_wells.mdb;Persist Security Info=False"
    rs.Open "wells_armavir", cn, adOpenDynamic, adLockPessimistic, adCmdTable
    For Each tbl In ActiveDocument.Tables
    f = 0
    For Each cl In tbl.Range.Cells
    rs.Fields(f).Value = GetCellText(cl)
    f = f + 1
    Next cl
    Next tbl

    End Sub

    Function GetCellText(cl As Word.Cell)
    Dim l As Integer

    l = Len(cl.Range.Text)
    GetCellText = Left$(cl.Range.Text, l - 2)
    End Function

    The VBA doesn't work for some reason and would like you to give your opinion on it too.

    I have attached two pages of the tables if it would help.

    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts