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.

Recommended Answers

All 4 Replies

Hi,

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

r = r + 1

Regards
Veena

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

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

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,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.