• Changing Outputted text from bold to regular

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Changing Outputted text from bold to regular

    Author
    Topic
    #462306

    In a previous post, I was working on outputting info from Access into a table in Word. I pretty well have that bit finished and have one final snag. For each table cell 2, the text “Group Sessions” is typed, a paragraph entered then the contents of the appropriate field from my recordset. I need “Group Sessions” to be regular and the info from the recordset to be bold. Like this:
    Group Session
    Budgeting and Money
    Management

    I don’t know enough about the Word object, particularly with ranges, etc to accomplish this. Here’s the complete code so you can see the context.

    [codebox]
    Private Const m_strDIR As String = “C:Documents and SettingsPeter NikiforukDesktopISAPISAP Activities”

    Public Sub WordClinnew()

    Dim wrdApp As Word.Application
    Dim wrdDoc As Word.Document
    Dim wrdTbl As Word.Table
    Dim c As Integer
    Dim n As Integer
    Dim r As Integer
    Dim cStart As Integer
    Dim rc As Integer
    Dim rst As DAO.Recordset
    Dim qdf As DAO.QueryDef
    Dim dbs As DAO.Database
    Dim dteStart As Date
    Dim dteEnd As Date
    Dim myRange As Range

    Set wrdApp = New Word.Application
    Set wrdDoc = wrdApp.Documents.Open(m_strDIR & “NIS – Template.DOC”)

    wrdApp.Visible = True
    dteStart = #4/1/2009#
    dteEnd = #4/30/2009#

    Set dbs = CurrentDb()
    Set qdf = dbs.QueryDefs(“qryGrpSessWord”)
    qdf.Parameters(“[forms]![frmISAPDates]![txtStartDate]”) = dteStart
    qdf.Parameters(“[forms]![frmISAPDates]![txtEndDate]”) = dteEnd

    Set rst = qdf.OpenRecordset(dbOpenDynaset)

    rc = rst.RecordCount
    n = rst.Fields.Count

    ‘ Go to table

    Set wrdTbl = wrdDoc.Tables(1)

    r = 1
    cStart = 0

    ‘ Loop through the records
    Do While Not rst.EOF
    r = r + 1

    cStart = cStart + 1

    ‘ Add a row
    wrdTbl.Rows.Add
    ‘ Fill from record
    wrdTbl.Cell(r, 1).Range.Bold = False
    wrdTbl.Cell(r, 1).Range.Text = cStart

    c = 2
    wrdTbl.Cell(r, c).Range.Bold = True
    wrdTbl.Cell(r, c).Range.Text = “Group Session” & vbCrLf & Nz(rst.Fields(c – 2).Value, 0)
    For c = 3 To n + 1
    wrdTbl.Cell(r, c).Range.Bold = False
    wrdTbl.Cell(r, c).Range.Text = Nz(rst.Fields(c – 2).Value, 0)
    ‘ Debug.Print rst.Fields(c – 2).Value

    Next c
    rst.MoveNext
    Loop

    wrdDoc.SaveAs FileName:=m_strDIR & _
    “Group sessions, itinerant services, partnerships” & FormatDateTime(Date, vbLongDate) & “.DOC”
    ‘ clean up
    rst.Close
    Set rst = Nothing

    End Sub [/codebox]

    Viewing 0 reply threads
    Author
    Replies
    • #1176228

      I’m not sure I have followed all the detail of your code, but to set an entire cell to be bold, except for the first two words, you can use syntax like…
      [indent]wrdTbl.Cell(r, c).Range.Font.Bold = True
      wrdTbl.Cell(r, c).Range.Words(1).Font.Bold = False
      wrdTbl.Cell(r, c).Range.Words(2).Font.Bold = False
      [/indent]

      • #1176233

        I’m not sure I have followed all the detail of your code, but to set an entire cell to be bold, except for the first two words, you can use syntax like…
        [indent]wrdTbl.Cell(r, c).Range.Font.Bold = True
        wrdTbl.Cell(r, c).Range.Words(1).Font.Bold = False
        wrdTbl.Cell(r, c).Range.Words(2).Font.Bold = False
        [/indent]

        Sweeeet!
        Never would have had the patience to figure that out and I certainly wouldn’t have looked there.

    Viewing 0 reply threads
    Reply To: Changing Outputted text from bold to regular

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: