Results 1 to 4 of 4

Thread: Table In Microsoft Word

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2002
    Location
    Rome, Italy
    Posts
    150

    Table In Microsoft Word

    I would like to make a table in a Microsoft Word document from a bunch or records in my Access database.

    How to do that?
    Catholics Do It With Beads

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Try this
    VB Code:
    1. Private Sub cmdMakeWordTable_Click()
    2. Dim MyWord As Object
    3. Dim x, y, res
    4.   x = 1
    5.   y = 1
    6. SQL = "SELECT name, type, address FROM MyTable  "
    7. Set Rs = Db.OpenRecordset(SQL, dbOpenDynaset, dbSQLPassThrough)
    8. Set MyWord = CreateObject("Word.Application")
    9.  
    10. With MyWord
    11.     .Documents.Add
    12.     .ActiveDocument.PageSetup.Orientation = wdOrientLandscape
    13.     .ActiveDocument.PageSetup.LeftMargin = 70
    14.     .ActiveDocument.PageSetup.TopMargin = 30
    15.     .Selection.Font.Name = "Verdana"
    16.    
    17.     res = .Application.ActiveDocument.Tables.Add _
    18.     (.Application.ActiveDocument.Range, Rs.RecordCount + 1, _
    19.     Rs.Fields.Count)
    20.         'Populating the Data from table
    21.         Do While Rs.EOF = False
    22.             .Application.ActiveDocument.Tables(1).Cell(x, y) = Rs.Fields(0)
    23.             .Application.ActiveDocument.Tables(1).Cell(x, y + 1) = Rs.Fields(1)
    24.             Rs.MoveNext
    25.             x = x + 1
    26.         Loop
    27. End With
    28. Set MyWord = Nothing
    29. End Sub

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2002
    Location
    Rome, Italy
    Posts
    150
    Thank you Mr. Hack.

    One more question. How to print it now?
    Catholics Do It With Beads

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Click on the Printer icon on the Word toolbar...

Posting Permissions

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



Click Here to Expand Forum to Full Width