This Code will Draw Tables in a Word(.doc) File and populate data from database
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
(2(2 Vote))
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
This Code will Draw Tables in a Word(.doc) File and populate data from database Comments
No comments yet — be the first to post one!
Post a Comment