Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    Dec 2002
    Location
    Kitchener, Ontario, Canada
    Posts
    421
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 Settings\Peter Nikiforuk\Desktop\ISAP\ISAP 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]

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts
    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...
    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

  3. #3
    4 Star Lounger
    Join Date
    Dec 2002
    Location
    Kitchener, Ontario, Canada
    Posts
    421
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='StuartR' post='792039' date='03-Sep-2009 18:54']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...
    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
    [/quote]

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •