Using the NextParagraphStyle property

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • klove1209
    New Member
    • Feb 2007
    • 32

    #1

    Using the NextParagraphStyle property

    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 nextparagraphst yle 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:

    Code:
    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
    Last edited by NeoPa; Feb 11 '07, 02:29 PM. Reason: Tags for Layout
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by klove1209
    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 nextparagraphst yle 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 "Applicatio n already running"
    Exit Function
    End If

    objApp.Visible = True

    'Add a document to the application

    Set objdoc = objApp.Document s.Add()


    strSQL = "SELECT SSR2_Table.Main SectionLabel, SSR2_Table.Main Label, SSR2_Table.Summ aryTextBox" & _
    " FROM (SSR_DataReport Name INNER JOIN SSR_DataReportL abels ON SSR_DataReportN ame.[DataReport ID]" & _
    " = SSR_DataReportL abels.DataRepor tID) INNER JOIN SSR2_Table ON SSR_DataReportL abels.DataRepor tID" & _
    " = SSR2_Table.Data ReportID WHERE (((SSR2_Table.D ataReportID)=1) );"

    rst3.Open strSQL, CurrentProject. Connection, adOpenKeyset, adLockPessimist ic


    'objdoc.Content .ParagraphForma t.style = wdStyleHeading1
    objdoc.Sections (1).Range.style = wdStyleHeading1
    gettbldata = rst3.Fields(0)
    objdoc.Content = gettbldata & vbCrLf

    gettbldata = rst3.Fields(1)
    ActiveDocument. Range.InsertAft er Text:=gettbldat a & vbCrLf & vbCrLf
    objdoc.Sentence s(2).style = wdStyleHeading8

    gettbldata = rst3.Fields(2)
    objdoc.Range.In sertAfter Text:=gettbldat a

    Set rst3 = Nothing
    End Function
    Here is the correct Syntax for the NextParagraphSt yle Property:

    Code:
    ActiveDocument.Styles(wdStyleHeading1).NextParagraphStyle = ActiveDocument.Styles(wdStyleHeading2)
            
    
    This example creates a new document and adds a paragraph style named "MyStyle." 
    The new style is based on the Normal style, is followed by the 
    Heading 3 style, has a left indent of 1 inch (72 points), and is bold.
    
    Set myDoc = Documents.Add
    Set myStyle = myDoc.Styles.Add(Name:= "MyStyle")
        With myStyle
            .BaseStyle = wdStyleNormal
            .NextParagraphStyle = wdStyleHeading3
            .ParagraphFormat.LeftIndent = 72
            .Font.Bold = True
        End With

    Comment

    Working...