Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to bring Content of word tables into access tables 1

Status
Not open for further replies.

JinanLebanon

Programmer
Oct 16, 2005
8
Good morning All

i have a nb of word docs with the same format,each containing 3 tables..
how can i import the content of each table into an access table?
thx in advance 2 all..
 
Thanx this is the method for just one table in a word document ..

i have at least three tables, the contents of each table (each with 2 columns, rows variable) must be transfered each to a table in MS ACCESS database..
 
It is possible to import several tables into Access from HTML documents; each table will be listed. It is possible to save Word documents as Web Pages.
 
Use automation to open an instance of Word in your code, open the documents, then parse through the table objects.

But something tells me that's not the "instant" answer you are looking for.

 
JinanLebanon said:
Any Other suggestions?

JinanLebanon said:
Nop this cannot be the answer neither the solution

Since you are just dismissing our suggestions without even an explanation why they would not work, I see little reason for me (or anyone else) to offer any new ideas.


 
OK here it is, Joe i'm sorry & everyone else i didn't mean it ok & i'm grateful 2 all your replies..

Private Sub button1_Click()
WrdFrstTable
ReturnCellText
End Sub
************
Sub ReturnCellText()
Dim wordpro As Word.Application
Dim tblOne As Table
Dim celTable As Cell
Dim rngTable As Range
Dim C As Integer
Dim T As Integer
Set tblOne = ActiveDocument.Tables(2)
T = tblOne.Rows.Count
For C = 1 To T
For Each celTable In tblOne.Rows(C).Cells
Set rngTable = celTable.Range
rngTable.MoveEnd Unit:=wdCharacter, Count:=-1
Me.SaderNb = SNum
If IsNumeric(rngTable) Then
Me.InRuleNb.SetFocus
Me.InRuleNb = rngTable.Text
Else
Me.InRuleText.SetFocus
Me.InRuleText = rngTable.Text
End If
Next celTable
DoCmd.GoToRecord , , acNewRec
Next C
End Sub
*******
Sub WrdFrstTable()
Dim wordpro As Word.Application
Dim tblOne As Table
Dim celTable As Cell
Dim rngTable As Range
Set tblOne = ActiveDocument.Tables(1)
For Each celTable In tblOne.Rows(1).Cells
Set rngTable = celTable.Range
rngTable.MoveEnd Unit:=wdCharacter, Count:=-1
SNum = rngTable.Text
Next celTable
End Sub

hope u will benefit from it
 
OK I am confused because this looks exactly like
"Use automation to open an instance of Word in your code, open the documents, then parse through the table objects"

Anyways this would be more efficient and stable if you work directly with the recordset using DAO or ADO then working with the form object and controls.
 
The code you posted is basically what I suggested, although I can't figure out if it's supposed to run in Word or Access. Using "ActiveDocument" by itself suggests the code is in Word, but you also use DoCmd, which as far as I know is only in Access.

Are you saying this code works for you?

If it's not I can probably make some suggestions.

 
Ok Joe any suggestions are welcomed as long as u r not upset :)
I've put this code on a button on a form in accessbut i only work when i open the word document in the same time, u know it's just testing

*****

Majp any other ideas r welcome..
 
I think you could get this to work in Access by itself with a few changes:
Code:
Sub ReturnCellText()
    Dim wordpro As Word.Application
    Dim tblOne As Table
    Dim celTable As Cell
    Dim rngTable As Range
    Dim C As Integer
    Dim T As Integer
[COLOR=blue]
    Set wordpro = New Word.Application
    wordpro.Documents.Open "C:\MyWordFile.doc"
    Set tblOne = wordpro.Documents(1).Tables(2)
[/color]
    T = tblOne.Rows.Count
        For C = 1 To T
            For Each celTable In tblOne.Rows(C).Cells
                 Set rngTable = celTable.Range
                 rngTable.MoveEnd Unit:=wdCharacter, Count:=-1
                 Me.SaderNb = SNum
                 If IsNumeric(rngTable) Then
                    Me.InRuleNb.SetFocus
                    Me.InRuleNb = rngTable.Text
                 Else
                    Me.InRuleText.SetFocus
                    Me.InRuleText = rngTable.Text
                 End If
            Next celTable
            DoCmd.GoToRecord , , acNewRec
        Next C
End Sub
That may not be the right spot to open your Word application. I think you might want to make it a module level variable and initialize it in the button1_click event.

Also, you should call the Quit method of the wordpro object once you are done with it.


 
Thx Joe i've added a browse button to choose the doc word, so no need to use this file of word precisely..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top