1,105,578 Community Members

vb6 report to word doc

Member Avatar
2mhzbrain
Light Poster
47 posts since Dec 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
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.

Member Avatar
QVeen72
Veteran Poster
1,016 posts since Nov 2006
Reputation Points: 104 [?]
Q&As Helped to Solve: 164 [?]
Skill Endorsements: 7 [?]
 
0
 

Hi,

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

r = r + 1

Regards
Veena

Member Avatar
2mhzbrain
Light Poster
47 posts since Dec 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
QVeen72
Veteran Poster
1,016 posts since Nov 2006
Reputation Points: 104 [?]
Q&As Helped to Solve: 164 [?]
Skill Endorsements: 7 [?]
 
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

Member Avatar
2mhzbrain
Light Poster
47 posts since Dec 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
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