I am trying to build a document within VB. I am currently outputting three recordsets from a query.
Each record set has a different paragraph style (Heading 1, Heading 8, and normal)
I have been trying to use the nextparagraphstyle property, but my document is still doing what it wants to do.
Below is a snippet of the code, and any assistance you have to offer is greatly appreciated:
Expand|Select|Wrap|Line Numbers
- Public Function gettbldata()
- Dim rst3 As New ADODB.Recordset
- Dim strSQL As String
- Dim objdoc As Word.Document
- If Not (objdoc Is Nothing) Then
- MsgBox "Application already running"
- Exit Function
- End If
- objApp.Visible = True
- 'Add a document to the application
- Set objdoc = objApp.Documents.Add()
- strSQL = "SELECT SSR2_Table.MainSectionLabel, SSR2_Table.MainLabel, SSR2_Table.SummaryTextBox" & _
- " FROM (SSR_DataReportName INNER JOIN SSR_DataReportLabels ON SSR_DataReportName.[DataReport ID]" & _
- " = SSR_DataReportLabels.DataReportID) INNER JOIN SSR2_Table ON SSR_DataReportLabels.DataReportID" & _
- " = SSR2_Table.DataReportID WHERE (((SSR2_Table.DataReportID)=1));"
- rst3.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockPessimistic
- 'objdoc.Content.ParagraphFormat.style = wdStyleHeading1
- objdoc.Sections(1).Range.style = wdStyleHeading1
- gettbldata = rst3.Fields(0)
- objdoc.Content = gettbldata & vbCrLf
- gettbldata = rst3.Fields(1)
- ActiveDocument.Range.InsertAfter Text:=gettbldata & vbCrLf & vbCrLf
- objdoc.Sentences(2).style = wdStyleHeading8
- gettbldata = rst3.Fields(2)
- objdoc.Range.InsertAfter Text:=gettbldata
- Set rst3 = Nothing
- End Function