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]