1.11M Members

vb6 report to word doc

 
0
 
    Dim oWord As Word.Application
    Dim oDoc As Word.Document
    Dim oTable As Word.Table
    Dim x As Integer


    Set oWord = CreateObject("Word.Application")
    oWord.Visible = True
    Set oDoc = oWord.Documents.Add

    Set rs = New ADODB.Recordset
    With rs
        .Open "SELECT * FROM ClientTable", cn, 2, 3

        Dim r As Integer, c As Integer
        Set oTable = oDoc.Tables.Add(oDoc.Bookmarks("\endofdoc").Range, rs.RecordCount, 5)
        oTable.Range.ParagraphFormat.SpaceAfter = 6

        'For r = 1 To rs.RecordCount
        Do While Not .EOF

            For c = 1 To 5
                oTable.Cell(r, c).Range.Text = rs(x).Value
                x = x + 1

            Next

        .MoveNext
        Loop
        'Next

        oTable.Rows(1).Range.Font.Bold = True

    End With
    Unload Me

It only displays the first row, and the font is not bold. Please help.

 
0
 

Hi,

After Do While Not .EOF
@ Line 21, write :

r = r + 1

Regards
Veena

 
0
 

another problem is, ID field is not displaying, primary and auto inc,

 
0
 

Hi,

Try Changing thr for loop:

For c = 1 To 5
    oTable.Cell(r, c).Range.Text = rs(c-1).Value
Next

Also, change the Query To:

"SELECT * FROM ClientTable Order By ID"

change FieldName accordingly..

Regards
Veena

 
0
 
For r = 1 To rs.RecordCount
    For c = 1 To 5
        oTable.Cell(r, c).Range.Text = rs(c - 1).Value
    Next
.MoveNext
Next

this works fine, thanks a lot, but how can i enable all the table lines,

Question Answered as of 1 Year Ago by QVeen72
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article