Is this possible? (Import Question)

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

I have an 11 page Word documement that is divided into 5
sections. I am creating an Access database to store the
info from the Word document. Rather than import the Word
info into one huge Access table, I want to import the info
into 5 separate tables in Access (one for each Word
section).

Is this possible? If so, how?

Thanks. I'm stumped.
 
Certainly. Here is a working sample.

Sub ExportToMdb()
Dim sec As Word.Section
Dim db As DAO.Database
Dim td As DAO.TableDef
Dim fld As DAO.Field
Dim rng As Range
Dim pCount As Integer
Set db = DBEngine.OpenDatabase("C:\WINNT\Profiles\aleksi\Desktop\test.mdb")
For Each sec In ActiveDocument.Sections
Debug.Print sec.Range.Text
Set td = New TableDef
With td
Set rng = sec.Range.Paragraphs(1).Range
'remove paragraph mark
rng.MoveEnd wdCharacter, -1
Set fld = New DAO.Field
fld.Name = "ID"
fld.Type = dbLong
fld.Attributes = dbAutoIncrField
.Fields.Append fld
Set fld = New DAO.Field
fld.Name = "Data"
fld.Type = dbText
fld.Size = 255
.Fields.Append fld
.Name = rng.Text
End With
db.TableDefs.Append td
For pCount = 2 To sec.Range.Paragraphs.Count
Set rng = sec.Range.Paragraphs(pCount).Range
rng.MoveEnd wdCharacter, -1
SQL = "insert into " _
& td.Name & " ([Data]) Values ('" _
& rng.Text & "')"
db.Execute SQL
Next
Next
End Sub
 
thanks

-----Original Message-----
Certainly. Here is a working sample.

Sub ExportToMdb()
Dim sec As Word.Section
Dim db As DAO.Database
Dim td As DAO.TableDef
Dim fld As DAO.Field
Dim rng As Range
Dim pCount As Integer
Set db = DBEngine.OpenDatabase ("C:\WINNT\Profiles\aleksi\Desktop\test.mdb")
For Each sec In ActiveDocument.Sections
Debug.Print sec.Range.Text
Set td = New TableDef
With td
Set rng = sec.Range.Paragraphs(1).Range
'remove paragraph mark
rng.MoveEnd wdCharacter, -1
Set fld = New DAO.Field
fld.Name = "ID"
fld.Type = dbLong
fld.Attributes = dbAutoIncrField
.Fields.Append fld
Set fld = New DAO.Field
fld.Name = "Data"
fld.Type = dbText
fld.Size = 255
.Fields.Append fld
.Name = rng.Text
End With
db.TableDefs.Append td
For pCount = 2 To sec.Range.Paragraphs.Count
Set rng = sec.Range.Paragraphs(pCount).Range
rng.MoveEnd wdCharacter, -1
SQL = "insert into " _
& td.Name & " ([Data]) Values ('" _
& rng.Text & "')"
db.Execute SQL
Next
Next
End Sub


I have an 11 page Word documement that is divided into 5
sections. I am creating an Access database to store the
info from the Word document. Rather than import the Word
info into one huge Access table, I want to import the info
into 5 separate tables in Access (one for each Word
section).

Is this possible? If so, how?

Thanks. I'm stumped.


.
 
Alex

I had a similar question, but with forms

Is it possible to export a *.doc, which has a lot of tables, into an Access form, then (let's say) map the tables' cells into specific fields in an Access table

R.
 
Back
Top