VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This Code will Draw Tables in a Word(.doc) File and populate data from database

by karada (6 Submissions)
Category: Files/File Controls/Input/Output
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Mon 8th January 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This Code will Draw Tables in a Word(.doc) File and populate data from database

API Declarations



'Start a new standardEXE project and add a command button named cmdWordWrite
'set a reference to
'1.Microsoft Word 9.0 object Library and
'2.Microsoft ActiveX data Object 2.1 Library.

Dim DataB as new ADODB.Connection
Dim Recset as new ADODB.Recordset



Rate This Code will Draw Tables in a Word(.doc) File and populate data from database




   DataB.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
   & App.Path & "\testDatabase.MDB"
   DataB.Open 
   RecSet.CursorLocation = adUseClient
   RecSet.CursorType = adOpenDynamic
   RecSet.LockType = adLockOptimistic
   RecSet.Open "testTable",DataB

End Sub


Private Sub cmdWordWrite_Click()
  Dim myword As Object
  Dim x,y
  x=1
  y=1
  
  Set myword = CreateObject("Word.Application")

With myword
        .Documents.Add
        .ActiveDocument.PageSetup.Orientation = wdOrientLandscape
        .ActiveDocument.PageSetup.LeftMargin = 70
        .ActiveDocument.PageSetup.TopMargin = 30
        .Selection.Font.Name = "Verdana"
        
        res = .Application.ActiveDocument.Tables.Add _  
        (.Application.ActiveDocument.Range, RecSet.RecordCount+1, _  
        RecSet.Fields.Count)

'Populating the Data from table

Do While RecSet.EOF = False
    .Application.ActiveDocument.Tables(1).Cell(x, y) = RecSet.Fields(0)
    
    .Application.ActiveDocument.Tables(1).Cell(x, y + 1) = RecSet.Fields(1)
    
    RecSet.MoveNext
    x = x + 1
    
Loop
End With
RecSet.Close
datab.Close

End Sub



Download this snippet    Add to My Saved Code

This Code will Draw Tables in a Word(.doc) File and populate data from database Comments

No comments have been posted about This Code will Draw Tables in a Word(.doc) File and populate data from database. Why not be the first to post a comment about This Code will Draw Tables in a Word(.doc) File and populate data from database.

Post your comment

Subject:
Message:
0/1000 characters