By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,490 Members | 897 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,490 IT Pros & Developers. It's quick & easy.

Using the NextParagraphStyle property

P: 32
Good afternoon all,

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
  1. Public Function gettbldata()
  2.  
  3. Dim rst3 As New ADODB.Recordset
  4. Dim strSQL As String
  5. Dim objdoc As Word.Document
  6.  
  7. If Not (objdoc Is Nothing) Then
  8.     MsgBox "Application already running"
  9.     Exit Function
  10. End If
  11.  
  12. objApp.Visible = True
  13.  
  14. 'Add a document to the application
  15.  
  16. Set objdoc = objApp.Documents.Add()
  17.  
  18.  
  19. strSQL = "SELECT SSR2_Table.MainSectionLabel, SSR2_Table.MainLabel, SSR2_Table.SummaryTextBox" & _
  20. " FROM (SSR_DataReportName INNER JOIN SSR_DataReportLabels ON SSR_DataReportName.[DataReport ID]" & _
  21. " = SSR_DataReportLabels.DataReportID) INNER JOIN SSR2_Table ON SSR_DataReportLabels.DataReportID" & _
  22. " = SSR2_Table.DataReportID WHERE (((SSR2_Table.DataReportID)=1));"
  23.  
  24. rst3.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockPessimistic
  25.  
  26.  
  27.     'objdoc.Content.ParagraphFormat.style = wdStyleHeading1
  28.     objdoc.Sections(1).Range.style = wdStyleHeading1
  29.     gettbldata = rst3.Fields(0)
  30.     objdoc.Content = gettbldata & vbCrLf
  31.  
  32.     gettbldata = rst3.Fields(1)
  33.     ActiveDocument.Range.InsertAfter Text:=gettbldata & vbCrLf & vbCrLf
  34.     objdoc.Sentences(2).style = wdStyleHeading8
  35.  
  36.     gettbldata = rst3.Fields(2)
  37.     objdoc.Range.InsertAfter Text:=gettbldata
  38.  
  39. Set rst3 = Nothing
  40. End Function
Feb 9 '07 #1
Share this Question
Share on Google+
1 Reply


ADezii
Expert 5K+
P: 8,597
Good afternoon all,

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:

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
Here is the correct Syntax for the NextParagraphStyle Property:

Expand|Select|Wrap|Line Numbers
  1. ActiveDocument.Styles(wdStyleHeading1).NextParagraphStyle = ActiveDocument.Styles(wdStyleHeading2)
  2.  
  3.  
  4. This example creates a new document and adds a paragraph style named "MyStyle." 
  5. The new style is based on the Normal style, is followed by the 
  6. Heading 3 style, has a left indent of 1 inch (72 points), and is bold.
  7.  
  8. Set myDoc = Documents.Add
  9. Set myStyle = myDoc.Styles.Add(Name:= "MyStyle")
  10.     With myStyle
  11.         .BaseStyle = wdStyleNormal
  12.         .NextParagraphStyle = wdStyleHeading3
  13.         .ParagraphFormat.LeftIndent = 72
  14.         .Font.Bold = True
  15.     End With
Feb 10 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.